uni.compiler.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. var compilerCore = require('@vue/compiler-core');
  7. function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
  8. var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefault(initMiniProgramPlugin);
  9. var path__default = /*#__PURE__*/_interopDefault(path);
  10. var setting = {
  11. urlCheck: false,
  12. es6: true,
  13. postcss: false,
  14. minified: false,
  15. newFeature: true
  16. };
  17. var appid = "testAppId";
  18. var projectname = "";
  19. var condition = {
  20. miniprogram: {
  21. current: -1
  22. }
  23. };
  24. var source = {
  25. setting: setting,
  26. appid: appid,
  27. projectname: projectname,
  28. condition: condition
  29. };
  30. function transformSwiper(node) {
  31. if (node.type !== 1 /* NodeTypes.ELEMENT */ || node.tag !== 'swiper') {
  32. return;
  33. }
  34. const disableTouchProp = compilerCore.findProp(node, 'disable-touch', false, true);
  35. if (!disableTouchProp) {
  36. return;
  37. }
  38. const { props } = node;
  39. if (disableTouchProp.type === 6 /* NodeTypes.ATTRIBUTE */) {
  40. // <swiper disable-touch/> => <swiper :touchable="false"/>
  41. props.splice(props.indexOf(disableTouchProp), 1, uniCliShared.createBindDirectiveNode('touchable', 'false'));
  42. }
  43. else {
  44. if (disableTouchProp.exp) {
  45. // <swiper :disable-touch="true"/> => <swiper :touchable="!(true)"/>
  46. let touchable = '';
  47. if (disableTouchProp.exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  48. if (disableTouchProp.exp.content === 'true') {
  49. touchable = 'false';
  50. }
  51. else if (disableTouchProp.exp.content === 'false') {
  52. touchable = 'true';
  53. }
  54. }
  55. props.splice(props.indexOf(disableTouchProp), 1, uniCliShared.createBindDirectiveNode('touchable', touchable || `!(${uniMpCompiler.genExpr(disableTouchProp.exp)})`));
  56. }
  57. }
  58. }
  59. const customElements = [
  60. 'aweme-data',
  61. 'consume-card',
  62. 'pay-button',
  63. 'rate-button',
  64. 'member-button',
  65. 'confirm-receipt-button',
  66. 'live-preview',
  67. 'aweme-live-book',
  68. 'aweme-user-card',
  69. 'rtc-room',
  70. ];
  71. const projectConfigFilename = 'project.config.json';
  72. const nodeTransforms = [
  73. uniCliShared.transformRef,
  74. transformSwiper,
  75. uniCliShared.transformMatchMedia,
  76. uniCliShared.transformComponentLink,
  77. ];
  78. const compilerOptions = {
  79. nodeTransforms,
  80. };
  81. const COMPONENTS_DIR = 'ttcomponents';
  82. const miniProgram = {
  83. class: {
  84. array: false,
  85. },
  86. slot: {
  87. fallbackContent: true,
  88. dynamicSlotNames: true,
  89. },
  90. directive: 'tt:',
  91. component: {
  92. dir: COMPONENTS_DIR,
  93. vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN_BIND,
  94. },
  95. };
  96. const options = {
  97. cdn: 4,
  98. vite: {
  99. inject: {
  100. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  101. },
  102. alias: {
  103. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  104. },
  105. copyOptions: {
  106. assets: [COMPONENTS_DIR],
  107. targets: [
  108. {
  109. src: ['ext.json'],
  110. get dest() {
  111. return process.env.UNI_OUTPUT_DIR;
  112. },
  113. },
  114. ],
  115. },
  116. },
  117. global: 'tt',
  118. app: {
  119. darkmode: false,
  120. subpackages: true,
  121. usingComponents: false,
  122. },
  123. project: {
  124. filename: projectConfigFilename,
  125. config: ['project.tt.json'],
  126. source,
  127. },
  128. template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
  129. extname: '.sjs',
  130. lang: 'sjs',
  131. generate(filter, filename) {
  132. if (filename) {
  133. return `<sjs src="${filename}.sjs" module="${filter.name}"/>`;
  134. }
  135. return `<sjs module="${filter.name}">
  136. ${filter.code}
  137. </sjs>`;
  138. },
  139. }, extname: '.ttml', compilerOptions }),
  140. style: {
  141. extname: '.ttss',
  142. },
  143. };
  144. const uniMiniProgramToutiaoPlugin = {
  145. name: 'uni:mp-toutiao',
  146. config() {
  147. return {
  148. define: {
  149. __VUE_CREATED_DEFERRED__: true,
  150. },
  151. build: {
  152. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  153. },
  154. };
  155. },
  156. };
  157. var index = [uniMiniProgramToutiaoPlugin, ...initMiniProgramPlugin__default.default(options)];
  158. module.exports = index;