uni.compiler.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 compilerCore = require('@vue/compiler-core');
  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 uniad_app_json = function (appJson) {
  10. if (!appJson.plugins) {
  11. appJson.plugins = {};
  12. }
  13. if (!appJson.plugins['uni-ad']) {
  14. appJson.plugins['uni-ad'] = {
  15. version: '1.1.10',
  16. provider: 'wxf72d316417b6767f',
  17. };
  18. }
  19. if (!appJson.plugins['coral-adv']) {
  20. appJson.plugins['coral-adv'] = {
  21. version: '1.0.18',
  22. provider: 'wx0e203209e27b1e66',
  23. };
  24. }
  25. if (!appJson.usingComponents) {
  26. appJson.usingComponents = {};
  27. }
  28. if (!appJson.usingComponents['uniad-plugin']) {
  29. appJson.usingComponents['uniad-plugin'] = 'plugin://uni-ad/ad';
  30. }
  31. };
  32. var uniadAppJson = uniad_app_json;
  33. const AD_COMPONENTS = [
  34. 'uniad',
  35. 'ad-rewarded-video',
  36. 'ad-fullscreen-video',
  37. 'ad-interstitial',
  38. ];
  39. let appJsonUniadFlag = false;
  40. function transformAd(node, context) {
  41. if (!uniCliShared.isElementNode(node)) {
  42. return;
  43. }
  44. const adpidProp = compilerCore.findProp(node, 'adpid');
  45. if (node.tag === 'ad' && adpidProp) {
  46. node.tag = 'uniad';
  47. node.tagType = 1 /* ElementTypes.COMPONENT */;
  48. }
  49. if (appJsonUniadFlag) {
  50. return;
  51. }
  52. if (AD_COMPONENTS.indexOf(node.tag) > -1) {
  53. appJsonUniadFlag = true;
  54. uniadAppJson(uniCliShared.findJsonFile('app'));
  55. }
  56. }
  57. var description = "项目配置文件。";
  58. var packOptions = {
  59. ignore: [
  60. ]
  61. };
  62. var setting = {
  63. urlCheck: false,
  64. es6: true,
  65. postcss: false,
  66. minified: false,
  67. newFeature: true,
  68. bigPackageSizeSupport: true
  69. };
  70. var compileType = "miniprogram";
  71. var libVersion = "";
  72. var appid = "touristappid";
  73. var projectname = "";
  74. var condition = {
  75. search: {
  76. current: -1,
  77. list: [
  78. ]
  79. },
  80. conversation: {
  81. current: -1,
  82. list: [
  83. ]
  84. },
  85. game: {
  86. current: -1,
  87. list: [
  88. ]
  89. },
  90. miniprogram: {
  91. current: -1,
  92. list: [
  93. ]
  94. }
  95. };
  96. var source = {
  97. description: description,
  98. packOptions: packOptions,
  99. setting: setting,
  100. compileType: compileType,
  101. libVersion: libVersion,
  102. appid: appid,
  103. projectname: projectname,
  104. condition: condition
  105. };
  106. const customElements = [
  107. 'page-container',
  108. 'page-meta',
  109. 'navigation-bar',
  110. 'match-media',
  111. 'ad-custom',
  112. 'share-element',
  113. 'channel-live',
  114. 'channel-video',
  115. 'voip-room',
  116. 'root-portal',
  117. 'subscribe',
  118. // 手势组件
  119. 'tap-gesture-handler',
  120. 'double-tap-gesture-handler',
  121. 'scale-gesture-handler',
  122. 'force-press-gesture-handler',
  123. 'pan-gesture-handler',
  124. 'vertical-drag-gesture-handler',
  125. 'horizontal-drag-gesture-handler',
  126. 'long-press-gesture-handler',
  127. 'grid-view',
  128. 'list-view',
  129. 'sticky-header',
  130. 'sticky-section',
  131. ];
  132. const compilerOptions = {
  133. nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink, transformAd],
  134. };
  135. const COMPONENTS_DIR = 'wxcomponents';
  136. const miniProgram = {
  137. class: {
  138. array: true,
  139. },
  140. slot: {
  141. fallbackContent: false,
  142. dynamicSlotNames: true,
  143. },
  144. event: {
  145. key: true,
  146. },
  147. directive: 'wx:',
  148. lazyElement: {
  149. canvas: [
  150. { name: 'bind', arg: ['canvas-id', 'id'] },
  151. {
  152. name: 'on',
  153. arg: ['touchstart', 'touchmove', 'touchcancel', 'touchend'],
  154. },
  155. ],
  156. editor: [
  157. {
  158. name: 'on',
  159. arg: ['ready'],
  160. },
  161. ],
  162. 'scroll-view': [
  163. {
  164. name: 'on',
  165. arg: ['dragstart', 'dragging', 'dragend'],
  166. },
  167. ],
  168. // iOS 平台需要延迟
  169. input: [{ name: 'bind', arg: ['type'] }],
  170. textarea: [{ name: 'on', arg: ['input'] }],
  171. },
  172. component: {
  173. dir: COMPONENTS_DIR,
  174. vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN,
  175. getPropertySync: false,
  176. normalizeName: (name) => name.startsWith('wx-') ? name.replace('wx-', 'weixin-') : name,
  177. },
  178. };
  179. const projectConfigFilename = 'project.config.json';
  180. const options = {
  181. cdn: 1,
  182. vite: {
  183. inject: {
  184. uni: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'default'],
  185. wx: [path__default.default.resolve(__dirname, 'uni.api.esm.js'), 'wx'],
  186. },
  187. alias: {
  188. 'uni-mp-runtime': path__default.default.resolve(__dirname, 'uni.mp.esm.js'),
  189. },
  190. copyOptions: {
  191. assets: [COMPONENTS_DIR],
  192. targets: [
  193. ...(process.env.UNI_MP_PLUGIN ? [uniCliShared.copyMiniProgramPluginJson] : []),
  194. {
  195. src: [
  196. 'sitemap.json',
  197. 'ext.json',
  198. 'custom-tab-bar',
  199. 'functional-pages',
  200. 'project.private.config.json',
  201. projectConfigFilename,
  202. ],
  203. get dest() {
  204. return process.env.UNI_OUTPUT_DIR;
  205. },
  206. },
  207. ...uniCliShared.copyMiniProgramThemeJson(),
  208. ],
  209. },
  210. },
  211. global: 'wx',
  212. app: {
  213. darkmode: true,
  214. subpackages: true,
  215. plugins: true,
  216. usingComponents: true,
  217. },
  218. project: {
  219. filename: projectConfigFilename,
  220. config: ['project.wx.json', 'project.config.json'],
  221. source,
  222. },
  223. template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
  224. extname: '.wxs',
  225. lang: 'wxs',
  226. generate(filter, filename) {
  227. if (filename) {
  228. return `<wxs src="${filename}.wxs" module="${filter.name}"/>`;
  229. }
  230. return `<wxs module="${filter.name}">
  231. ${filter.code}
  232. </wxs>`;
  233. },
  234. }, extname: '.wxml', compilerOptions }),
  235. style: {
  236. extname: '.wxss',
  237. },
  238. };
  239. const uniMiniProgramWeixinPlugin = {
  240. name: 'uni:mp-weixin',
  241. config() {
  242. return {
  243. define: {
  244. __VUE_CREATED_DEFERRED__: false,
  245. },
  246. build: {
  247. // css 中不支持引用本地资源
  248. assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
  249. },
  250. };
  251. },
  252. };
  253. var index = [uniMiniProgramWeixinPlugin, ...initMiniProgramPlugin__default.default(options)];
  254. module.exports = index;