uni.compiler.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 compileType = "miniprogram";
  9. var setting = {
  10. es6: true
  11. };
  12. var source = {
  13. compileType: compileType,
  14. setting: setting
  15. };
  16. // import { transformSwiper } from './transforms/transformSwiper'
  17. const projectConfigFilename = 'project.config.json';
  18. const nodeTransforms = [
  19. uniCliShared.transformRef,
  20. // transformMatchMedia,
  21. uniCliShared.transformComponentLink,
  22. ];
  23. const compilerOptions = {
  24. nodeTransforms,
  25. };
  26. const COMPONENTS_DIR = 'jdcomponents';
  27. const miniProgram = {
  28. class: {
  29. /**
  30. * 是否支持绑定 array 类型
  31. */
  32. array: false,
  33. },
  34. slot: {
  35. /**
  36. * 是否支持后备内容
  37. */
  38. fallbackContent: true,
  39. /**
  40. * 是否支持动态插槽名
  41. */
  42. dynamicSlotNames: true,
  43. },
  44. directive: 'jd:',
  45. component: {
  46. dir: COMPONENTS_DIR,
  47. vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN_BIND,
  48. // 父组件 setData 后,子组件的 properties 是否可以同步获取
  49. getPropertySync: false,
  50. },
  51. };
  52. const options = {
  53. // ?
  54. cdn: 11,
  55. vite: {
  56. inject: {
  57. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  58. },
  59. alias: {
  60. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  61. },
  62. copyOptions: {
  63. /**
  64. * 静态资源,配置的目录,在 uni_modules 中同样支持
  65. */
  66. assets: [COMPONENTS_DIR],
  67. targets: [
  68. {
  69. // FileWatcher这个类监听的文件,文件改动触发整体编译?编译什么?
  70. src: ['project.config.json', 'custom-tab-bar'],
  71. // 输出目录
  72. get dest() {
  73. return process.env.UNI_OUTPUT_DIR;
  74. },
  75. },
  76. ],
  77. },
  78. },
  79. global: 'jd',
  80. app: {
  81. /**
  82. * 是否支持darkmode
  83. */
  84. darkmode: true,
  85. /**
  86. * 是否支持subpackages
  87. */
  88. subpackages: true,
  89. /**
  90. * 是否支持发行插件
  91. */
  92. plugins: true,
  93. /**
  94. * 是否支持全局组件
  95. */
  96. usingComponents: true,
  97. },
  98. project: {
  99. filename: projectConfigFilename,
  100. config: ['project.config.json'],
  101. source,
  102. },
  103. // 对模版的编译处理
  104. template: Object.assign(Object.assign({}, miniProgram), { filter: {
  105. extname: '.jds',
  106. lang: 'jds',
  107. generate(filter, filename) {
  108. if (filename) {
  109. return `<jds src="${filename}.jds" module="${filter.name}"/>`;
  110. }
  111. return `<jds module="${filter.name}">
  112. ${filter.code}
  113. </jds>`;
  114. },
  115. }, extname: '.jxml', compilerOptions }),
  116. style: {
  117. extname: '.jxss',
  118. },
  119. };
  120. const uniMiniProgramJdPlugin = {
  121. name: 'uni:mp-jd',
  122. config() {
  123. return {
  124. define: {
  125. __VUE_CREATED_DEFERRED__: false,
  126. },
  127. build: {
  128. // 图片资源转行内base64最大size限制
  129. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  130. },
  131. };
  132. },
  133. };
  134. var index = [uniMiniProgramJdPlugin, ...initMiniProgramPlugin__default.default(options)];
  135. module.exports = index;