uni.compiler.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 shared = require('@vue/shared');
  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 compilerOptions$1 = {
  10. target: "es6",
  11. module: "commonjs"
  12. };
  13. var source = {
  14. compilerOptions: compilerOptions$1
  15. };
  16. const properties = ['name', 'versionName', 'versionCode'];
  17. function formatAppJson(_appJson, manifestJson, _pagesJson) {
  18. const appJson = _appJson;
  19. // 华为IDE V3.0.2+ 需要此属性,否则无法导入
  20. appJson.appType = 'webapp';
  21. appJson.minPlatformVersion = 1070;
  22. properties.forEach((name) => {
  23. if (shared.hasOwn(manifestJson, name)) {
  24. appJson[name] = manifestJson[name];
  25. }
  26. });
  27. if (!appJson.name) {
  28. const inputDir = process.env.UNI_INPUT_DIR;
  29. let projectname = path__default.default.basename(inputDir);
  30. if (projectname === 'src') {
  31. projectname = path__default.default.basename(path__default.default.dirname(inputDir));
  32. }
  33. appJson.name = projectname;
  34. }
  35. if (!appJson.package) {
  36. appJson.package = appJson.name;
  37. }
  38. if (manifestJson['quickapp-webview']) {
  39. shared.extend(appJson, manifestJson['quickapp-webview']);
  40. }
  41. if (process.env.UNI_SUB_PLATFORM &&
  42. manifestJson[process.env.UNI_SUB_PLATFORM]) {
  43. shared.extend(appJson, manifestJson[process.env.UNI_SUB_PLATFORM]);
  44. }
  45. if (!appJson.package) {
  46. console.warn('manifest.json->quickapp-webview 缺少 package 配置');
  47. }
  48. if (!appJson.icon) {
  49. console.warn('manifest.json->quickapp-webview 缺少 icon 配置');
  50. }
  51. }
  52. const compilerOptions = {
  53. nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink],
  54. };
  55. const miniProgram = {
  56. class: {
  57. array: true,
  58. },
  59. slot: {
  60. fallbackContent: true,
  61. dynamicSlotNames: true,
  62. },
  63. directive: 'qa:',
  64. };
  65. const projectConfigFilename = 'jsconfig.json';
  66. const options = {
  67. cdn: process.env.UNI_SUB_PLATFORM === 'quickapp-webview-huawei' ? 200 : 201,
  68. vite: {
  69. inject: {
  70. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  71. },
  72. alias: {
  73. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  74. },
  75. copyOptions: {},
  76. },
  77. global: 'qa',
  78. app: {
  79. darkmode: false,
  80. subpackages: true,
  81. usingComponents: true,
  82. },
  83. json: {
  84. formatAppJson,
  85. },
  86. template: Object.assign(Object.assign({}, miniProgram), { filter: {
  87. extname: '.qjs',
  88. lang: 'qjs',
  89. generate(filter, filename) {
  90. if (filename) {
  91. return `<qjs src="${filename}.qjs" module="${filter.name}"/>`;
  92. }
  93. return `<qjs module="${filter.name}">
  94. ${filter.code}
  95. </qjs>`;
  96. },
  97. }, extname: '.qxml', compilerOptions }),
  98. style: {
  99. extname: '.css',
  100. },
  101. project: {
  102. filename: projectConfigFilename,
  103. config: [],
  104. source,
  105. },
  106. };
  107. const uniQuickappWebviewPlugin = {
  108. name: 'uni:quickapp-webview',
  109. config() {
  110. return {
  111. define: {
  112. __VUE_CREATED_DEFERRED__: true,
  113. },
  114. build: {
  115. // css 中不支持引用本地资源
  116. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  117. },
  118. };
  119. },
  120. };
  121. var index = [uniQuickappWebviewPlugin, ...initMiniProgramPlugin__default.default(options)];
  122. module.exports = index;