uni.compiler.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
  6. var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefault(initMiniProgramPlugin);
  7. var path__default = /*#__PURE__*/_interopDefault(path);
  8. var description = "项目配置文件。";
  9. var packOptions = {
  10. ignore: [
  11. ]
  12. };
  13. var setting = {
  14. urlCheck: false,
  15. es6: true,
  16. postcss: false,
  17. minified: false,
  18. newFeature: true,
  19. bigPackageSizeSupport: true
  20. };
  21. var compileType = "miniprogram";
  22. var libVersion = "";
  23. var appid = "touristappid";
  24. var projectname = "";
  25. var condition = {
  26. search: {
  27. current: -1,
  28. list: [
  29. ]
  30. },
  31. conversation: {
  32. current: -1,
  33. list: [
  34. ]
  35. },
  36. game: {
  37. current: -1,
  38. list: [
  39. ]
  40. },
  41. miniprogram: {
  42. current: -1,
  43. list: [
  44. ]
  45. }
  46. };
  47. var source = {
  48. description: description,
  49. packOptions: packOptions,
  50. setting: setting,
  51. compileType: compileType,
  52. libVersion: libVersion,
  53. appid: appid,
  54. projectname: projectname,
  55. condition: condition
  56. };
  57. const directiveTransforms = {};
  58. const compilerOptions = {
  59. nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink, uniCliShared.transformMatchMedia],
  60. directiveTransforms,
  61. };
  62. const COMPONENTS_DIR = 'xhscomponents';
  63. const miniProgram = {
  64. class: {
  65. array: false,
  66. },
  67. slot: {
  68. fallbackContent: false,
  69. dynamicSlotNames: false,
  70. },
  71. event: {
  72. key: true,
  73. },
  74. directive: 'xhs:',
  75. lazyElement: {
  76. canvas: [
  77. { name: 'bind', arg: ['canvas-id', 'id'] },
  78. {
  79. name: 'on',
  80. arg: ['touchstart', 'touchmove', 'touchcancel', 'touchend'],
  81. },
  82. ],
  83. editor: [
  84. {
  85. name: 'on',
  86. arg: ['ready'],
  87. },
  88. ],
  89. 'scroll-view': [
  90. {
  91. name: 'on',
  92. arg: ['dragstart', 'dragging', 'dragend'],
  93. },
  94. ],
  95. // iOS 平台需要延迟
  96. input: [{ name: 'bind', arg: ['type'] }],
  97. textarea: [{ name: 'on', arg: ['input'] }],
  98. },
  99. component: {
  100. dir: COMPONENTS_DIR,
  101. },
  102. };
  103. const projectConfigFilename = 'project.config.json';
  104. const options = {
  105. cdn: 12,
  106. vite: {
  107. inject: {
  108. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  109. },
  110. alias: {
  111. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  112. },
  113. copyOptions: {
  114. assets: [COMPONENTS_DIR],
  115. targets: [
  116. // ...(process.env.UNI_MP_PLUGIN ? [copyMiniProgramPluginJson] : []),
  117. {
  118. src: [
  119. 'sitemap.json',
  120. 'project.private.config.json',
  121. projectConfigFilename,
  122. ],
  123. get dest() {
  124. return process.env.UNI_OUTPUT_DIR;
  125. },
  126. },
  127. // ...copyMiniProgramThemeJson(),
  128. ],
  129. },
  130. },
  131. global: 'xhs',
  132. app: {
  133. darkmode: false,
  134. subpackages: true,
  135. usingComponents: true,
  136. },
  137. project: {
  138. filename: projectConfigFilename,
  139. config: ['project.config.json'],
  140. source,
  141. },
  142. template: Object.assign(Object.assign({}, miniProgram), { filter: {
  143. extname: '.sjs',
  144. lang: 'sjs',
  145. generate(filter, filename) {
  146. return `<sjs src="${filename}.sjs" module="${filter.name}"/>`;
  147. },
  148. }, extname: '.xhsml', compilerOptions }),
  149. style: {
  150. extname: '.css',
  151. },
  152. };
  153. const uniMiniProgramXhsPlugin = {
  154. name: 'uni:mp-xhs',
  155. config() {
  156. return {
  157. define: {
  158. __VUE_CREATED_DEFERRED__: false,
  159. },
  160. build: {
  161. // 图片资源转行内base64最大size限制
  162. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  163. },
  164. };
  165. },
  166. };
  167. var index = [uniMiniProgramXhsPlugin, ...initMiniProgramPlugin__default.default(options)];
  168. module.exports = index;