uni.compiler.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 uniMpCompiler = require('@dcloudio/uni-mp-compiler');
  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 description = "项目配置文件";
  10. var packOptions = {
  11. ignore: [
  12. ]
  13. };
  14. var setting = {
  15. urlCheck: false,
  16. es6: true,
  17. enhance: false,
  18. postcss: true,
  19. preloadBackgroundData: false,
  20. minified: true,
  21. newFeature: false,
  22. coverView: true,
  23. nodeModules: false,
  24. autoAudits: false,
  25. showShadowRootInWxmlPanel: true,
  26. scopeDataCheck: false,
  27. uglifyFileName: false,
  28. checkInvalidKey: true,
  29. checkSiteMap: true,
  30. uploadWithSourceMap: true,
  31. compileHotReLoad: false,
  32. babelSetting: {
  33. ignore: [
  34. ],
  35. disablePlugins: [
  36. ],
  37. outputPath: ""
  38. },
  39. useIsolateContext: true,
  40. useCompilerModule: false,
  41. userConfirmedUseCompilerModuleSwitch: false
  42. };
  43. var compileType = "miniprogram";
  44. var libVersion = "";
  45. var appid = "";
  46. var projectname = "";
  47. var debugOptions = {
  48. hidedInDevtools: [
  49. ]
  50. };
  51. var scripts = {
  52. };
  53. var isGameTourist = false;
  54. var simulatorPluginLibVersion = {
  55. };
  56. var condition = {
  57. search: {
  58. current: -1,
  59. list: [
  60. ]
  61. },
  62. conversation: {
  63. current: -1,
  64. list: [
  65. ]
  66. },
  67. game: {
  68. current: -1,
  69. list: [
  70. ]
  71. },
  72. plugin: {
  73. current: -1,
  74. list: [
  75. ]
  76. },
  77. gamePlugin: {
  78. current: -1,
  79. list: [
  80. ]
  81. },
  82. miniprogram: {
  83. current: -1,
  84. list: [
  85. ]
  86. }
  87. };
  88. var source = {
  89. description: description,
  90. packOptions: packOptions,
  91. setting: setting,
  92. compileType: compileType,
  93. libVersion: libVersion,
  94. appid: appid,
  95. projectname: projectname,
  96. debugOptions: debugOptions,
  97. scripts: scripts,
  98. isGameTourist: isGameTourist,
  99. simulatorPluginLibVersion: simulatorPluginLibVersion,
  100. condition: condition
  101. };
  102. /**
  103. * 快手小程序的自定义组件,不支持动态事件绑定
  104. */
  105. const transformOn = uniCliShared.createTransformOn(uniMpCompiler.transformOn, {
  106. match: (name, node, context) => {
  107. if (name === 'getphonenumber')
  108. return true;
  109. if (name === 'input' && (node.tag === 'input' || node.tag === 'textarea')) {
  110. return true;
  111. }
  112. return uniCliShared.matchTransformOn(name, node, context);
  113. },
  114. });
  115. /**
  116. * 快手小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整,其中 input、textarea 也不支持
  117. */
  118. const transformModel = uniCliShared.createTransformModel(uniMpCompiler.transformModel, {
  119. match: (node, context) => {
  120. if (node.tag === 'input' || node.tag === 'textarea') {
  121. return true;
  122. }
  123. return uniCliShared.matchTransformModel(node, context);
  124. },
  125. });
  126. const nodeTransforms = [uniCliShared.transformRef, uniCliShared.transformComponentLink];
  127. const directiveTransforms = {
  128. on: transformOn,
  129. model: transformModel,
  130. };
  131. const compilerOptions = {
  132. nodeTransforms,
  133. directiveTransforms,
  134. };
  135. const COMPONENTS_DIR = 'kscomponents';
  136. const miniProgram = {
  137. class: {
  138. array: false,
  139. },
  140. slot: {
  141. fallbackContent: false,
  142. dynamicSlotNames: false,
  143. },
  144. directive: 'ks:',
  145. lazyElement: {
  146. switch: [{ name: 'on', arg: ['change'] }],
  147. },
  148. component: {
  149. dir: COMPONENTS_DIR,
  150. },
  151. };
  152. const projectConfigFilename = 'project.config.json';
  153. const options = {
  154. cdn: 9,
  155. vite: {
  156. inject: {
  157. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  158. },
  159. alias: {
  160. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  161. },
  162. copyOptions: {
  163. assets: [COMPONENTS_DIR],
  164. targets: [
  165. {
  166. src: ['ext.json'],
  167. get dest() {
  168. return process.env.UNI_OUTPUT_DIR;
  169. },
  170. },
  171. ],
  172. },
  173. },
  174. global: 'ks',
  175. app: {
  176. darkmode: false,
  177. subpackages: true,
  178. usingComponents: true,
  179. },
  180. project: {
  181. filename: projectConfigFilename,
  182. config: ['project.ks.json'],
  183. source,
  184. },
  185. template: Object.assign(Object.assign({}, miniProgram), { filter: undefined, extname: '.ksml', compilerOptions }),
  186. style: {
  187. extname: '.css',
  188. },
  189. };
  190. const uniMiniProgramKuaishouPlugin = {
  191. name: 'uni:mp-kuaishou',
  192. config() {
  193. return {
  194. define: {
  195. __VUE_CREATED_DEFERRED__: false,
  196. },
  197. build: {
  198. // css 中不支持引用本地资源
  199. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  200. },
  201. };
  202. },
  203. };
  204. var index = [uniMiniProgramKuaishouPlugin, ...initMiniProgramPlugin__default.default(options)];
  205. module.exports = index;