uni.compiler.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. 'use strict';
  2. var uniCliShared = require('@dcloudio/uni-cli-shared');
  3. var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
  4. var path = require('path');
  5. var fs = require('fs-extra');
  6. function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
  7. var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefault(initMiniProgramPlugin);
  8. var path__default = /*#__PURE__*/_interopDefault(path);
  9. var fs__default = /*#__PURE__*/_interopDefault(fs);
  10. let isFixed = false;
  11. function fix2648(bundle) {
  12. if (isFixed) {
  13. return;
  14. }
  15. const appJsonAsset = bundle['app.json'];
  16. if (!appJsonAsset) {
  17. return;
  18. }
  19. try {
  20. const { usingComponents } = JSON.parse(appJsonAsset.source.toString());
  21. if (usingComponents && usingComponents['fix-2648']) {
  22. fs__default.default.outputFileSync(path__default.default.resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.json'), `{"component":true}`);
  23. fs__default.default.outputFileSync(path__default.default.resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.qml'), `<!-- https://github.com/dcloudio/uni-app/issues/2648 -->`);
  24. fs__default.default.outputFileSync(path__default.default.resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.js'), `Component({})`);
  25. }
  26. isFixed = true;
  27. }
  28. catch (_a) { }
  29. }
  30. var description = "项目配置文件。";
  31. var packOptions = {
  32. ignore: [
  33. ]
  34. };
  35. var setting = {
  36. urlCheck: true,
  37. es6: true,
  38. postcss: false,
  39. minified: false,
  40. newFeature: true,
  41. nodeModules: false
  42. };
  43. var compileType = "miniprogram";
  44. var libVersion = "";
  45. var appid = "touristappid";
  46. var projectname = "";
  47. var condition = {
  48. search: {
  49. current: -1,
  50. list: [
  51. ]
  52. },
  53. conversation: {
  54. current: -1,
  55. list: [
  56. ]
  57. },
  58. game: {
  59. current: -1,
  60. list: [
  61. ]
  62. },
  63. miniprogram: {
  64. current: -1,
  65. list: [
  66. ]
  67. }
  68. };
  69. var source = {
  70. description: description,
  71. packOptions: packOptions,
  72. setting: setting,
  73. compileType: compileType,
  74. libVersion: libVersion,
  75. appid: appid,
  76. projectname: projectname,
  77. condition: condition
  78. };
  79. const nodeTransforms = [
  80. uniCliShared.transformRef,
  81. uniCliShared.transformMatchMedia,
  82. uniCliShared.transformComponentLink,
  83. ];
  84. const compilerOptions = {
  85. nodeTransforms,
  86. };
  87. const COMPONENTS_DIR = 'wxcomponents';
  88. const miniProgram = {
  89. class: {
  90. array: true,
  91. },
  92. slot: {
  93. fallbackContent: false,
  94. dynamicSlotNames: true,
  95. },
  96. event: {
  97. key: true,
  98. },
  99. directive: 'qq:',
  100. lazyElement: {
  101. editor: [
  102. {
  103. name: 'on',
  104. arg: ['ready'],
  105. },
  106. ],
  107. video: [
  108. {
  109. name: 'on',
  110. arg: [
  111. 'play',
  112. 'pause',
  113. 'ended',
  114. 'timeupdate',
  115. 'fullscreenchange',
  116. 'waiting',
  117. 'error',
  118. 'progress',
  119. ],
  120. },
  121. ],
  122. },
  123. component: {
  124. dir: COMPONENTS_DIR,
  125. vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN,
  126. getPropertySync: false, // 为了避免 Setting data field "uP" to undefined is invalid 警告
  127. },
  128. };
  129. const options = {
  130. cdn: 5,
  131. vite: {
  132. inject: {
  133. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  134. },
  135. alias: {
  136. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  137. },
  138. copyOptions: {
  139. assets: [COMPONENTS_DIR],
  140. targets: [
  141. {
  142. src: ['custom-tab-bar'],
  143. get dest() {
  144. return process.env.UNI_OUTPUT_DIR;
  145. },
  146. },
  147. ],
  148. },
  149. },
  150. global: 'qq',
  151. app: {
  152. darkmode: false,
  153. subpackages: true,
  154. usingComponents: true,
  155. normalize(appJson) {
  156. const hasUsingComponents = appJson.usingComponents && Object.keys(appJson.usingComponents).length;
  157. if (!hasUsingComponents) {
  158. // fix https://github.com/dcloudio/uni-app/issues/2648
  159. appJson.usingComponents = {
  160. 'fix-2648': '/fix-2648',
  161. };
  162. }
  163. return appJson;
  164. },
  165. },
  166. project: {
  167. filename: 'project.config.json',
  168. config: ['project.qq.json', 'project.config.json'],
  169. source,
  170. normalize(projectJson) {
  171. projectJson.qqappid = projectJson.appid;
  172. projectJson.qqLibVersion = projectJson.libVersion;
  173. delete projectJson.appid;
  174. delete projectJson.libVersion;
  175. return projectJson;
  176. },
  177. },
  178. template: Object.assign(Object.assign({}, miniProgram), { filter: {
  179. extname: '.qs',
  180. lang: 'wxs',
  181. generate(filter, filename) {
  182. if (filename) {
  183. return `<qs src="${filename}.qs" module="${filter.name}"/>`;
  184. }
  185. return `<qs module="${filter.name}">
  186. ${filter.code}
  187. </qs>`;
  188. },
  189. }, extname: '.qml', compilerOptions }),
  190. style: {
  191. extname: '.qss',
  192. },
  193. };
  194. const uniMiniProgramQQPlugin = {
  195. name: 'uni:mp-qq',
  196. config() {
  197. return {
  198. define: {
  199. __VUE_CREATED_DEFERRED__: false,
  200. },
  201. build: {
  202. // css 中不支持引用本地资源
  203. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  204. },
  205. };
  206. },
  207. writeBundle(_, bundle) {
  208. fix2648(bundle);
  209. },
  210. };
  211. var index = [uniMiniProgramQQPlugin, ...initMiniProgramPlugin__default.default(options)];
  212. module.exports = index;