@mpxjs/webpack-plugin 2.8.40-test → 2.8.40-test.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/lib/dependencies/DynamicEntryDependency.js +10 -16
  2. package/lib/index.js +87 -60
  3. package/lib/json-compiler/helper.js +8 -5
  4. package/lib/json-compiler/index.js +2 -2
  5. package/lib/loader.js +28 -27
  6. package/lib/parser.js +0 -1
  7. package/lib/platform/index.js +15 -4
  8. package/lib/platform/json/wx/index.js +3 -5
  9. package/lib/platform/run-rules.js +1 -2
  10. package/lib/platform/template/normalize-component-rules.js +41 -42
  11. package/lib/platform/template/wx/component-config/component.js +1 -2
  12. package/lib/platform/template/wx/component-config/fix-component-name.js +21 -0
  13. package/lib/platform/template/wx/component-config/index.js +4 -4
  14. package/lib/platform/template/wx/index.js +21 -16
  15. package/lib/runtime/base.styl +9 -1
  16. package/lib/runtime/components/web/getInnerListeners.js +1 -2
  17. package/lib/runtime/components/web/mpx-image.vue +13 -10
  18. package/lib/runtime/components/web/mpx-movable-view.vue +1 -1
  19. package/lib/runtime/components/web/mpx-picker-view-column.vue +10 -2
  20. package/lib/runtime/components/web/mpx-picker.vue +9 -1
  21. package/lib/runtime/components/web/mpx-swiper.vue +2 -2
  22. package/lib/runtime/optionProcessor.js +321 -264
  23. package/lib/runtime/stringify.wxs +44 -8
  24. package/lib/style-compiler/index.js +1 -2
  25. package/lib/template-compiler/compiler.js +74 -56
  26. package/lib/utils/check-core-version-match.js +18 -14
  27. package/lib/web/processJSON.js +4 -3
  28. package/lib/web/processMainScript.js +84 -0
  29. package/lib/web/processScript.js +21 -204
  30. package/lib/web/processTemplate.js +4 -1
  31. package/lib/web/script-helper.js +202 -0
  32. package/package.json +5 -4
  33. package/lib/platform/template/wx/component-config/fix-html-tag.js +0 -17
  34. package/lib/style-compiler/plugins/trim.js +0 -15
@@ -1,33 +1,8 @@
1
1
  const genComponentTag = require('../utils/gen-component-tag')
2
2
  const loaderUtils = require('loader-utils')
3
- const addQuery = require('../utils/add-query')
4
3
  const normalize = require('../utils/normalize')
5
- const hasOwn = require('../utils/has-own')
6
- const createHelpers = require('../helpers')
7
4
  const optionProcessorPath = normalize.lib('runtime/optionProcessor')
8
- const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
9
- const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
10
-
11
- function shallowStringify (obj) {
12
- const arr = []
13
- for (const key in obj) {
14
- if (hasOwn(obj, key)) {
15
- let value = obj[key]
16
- if (Array.isArray(value)) {
17
- value = `[${value.join(',')}]`
18
- }
19
- arr.push(`'${key}':${value}`)
20
- }
21
- }
22
- return `{${arr.join(',')}}`
23
- }
24
-
25
- function getAsyncChunkName (chunkName) {
26
- if (chunkName && typeof chunkName !== 'boolean') {
27
- return `/* webpackChunkName: "${chunkName}" */`
28
- }
29
- return ''
30
- }
5
+ const { buildComponentsMap, getRequireScript, buildGlobalParams, shallowStringify } = require('./script-helper')
31
6
 
32
7
  module.exports = function (script, {
33
8
  loaderContext,
@@ -38,50 +13,14 @@ module.exports = function (script, {
38
13
  componentGenerics,
39
14
  jsonConfig,
40
15
  outputPath,
41
- tabBarMap,
42
- tabBarStr,
43
16
  builtInComponentsMap,
44
17
  genericsInfo,
45
18
  wxsModuleMap,
46
- localComponentsMap,
47
- localPagesMap
19
+ localComponentsMap
48
20
  }, callback) {
49
- const {
50
- i18n,
51
- projectRoot,
52
- webConfig,
53
- appInfo
54
- } = loaderContext.getMpx()
55
- const { getRequire } = createHelpers(loaderContext)
56
- const tabBar = jsonConfig.tabBar
57
-
58
- const emitWarning = (msg) => {
59
- loaderContext.emitWarning(
60
- new Error('[script processor][' + loaderContext.resource + ']: ' + msg)
61
- )
62
- }
21
+ const { projectRoot, appInfo } = loaderContext.getMpx()
63
22
 
64
23
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
65
- const tabBarPagesMap = {}
66
- if (tabBar && tabBarMap) {
67
- // 挂载tabBar组件
68
- const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
69
- tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
70
- // 挂载tabBar页面
71
- Object.keys(tabBarMap).forEach((pagePath) => {
72
- const pageCfg = localPagesMap[pagePath]
73
- if (pageCfg) {
74
- const pageRequest = stringifyRequest(pageCfg.resource)
75
- if (pageCfg.async) {
76
- tabBarPagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
77
- } else {
78
- tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
79
- }
80
- } else {
81
- emitWarning(`TabBar page path ${pagePath} is not exist in local page map, please check!`)
82
- }
83
- })
84
- }
85
24
 
86
25
  let output = '/* script */\n'
87
26
 
@@ -101,59 +40,7 @@ module.exports = function (script, {
101
40
  return attrs
102
41
  },
103
42
  content (script) {
104
- let content = `\n import processOption, { getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
105
- // add import
106
- if (ctorType === 'app') {
107
- content += ` import '@mpxjs/webpack-plugin/lib/runtime/base.styl'
108
- import Vue from 'vue'
109
- import VueRouter from 'vue-router'
110
- import Mpx from '@mpxjs/core'
111
- Vue.use(VueRouter)
112
- global.getApp = function(){}
113
- global.getCurrentPages = function(){
114
- const router = global.__mpxRouter
115
- if(!router) return []
116
- // @ts-ignore
117
- return (router.lastStack || router.stack).map(item => {
118
- let page
119
- const vnode = item.vnode
120
- if(vnode && vnode.componentInstance) {
121
- page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
122
- }
123
- return page || { route: item.path.slice(1) }
124
- })
125
- }
126
- global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
127
- global.__mpxGenericsMap = {}
128
- global.__mpxOptionsMap = {}
129
- global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
130
- global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
131
- global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
132
- if (i18n) {
133
- const i18nObj = Object.assign({}, i18n)
134
- content += ` import VueI18n from 'vue-i18n'
135
- import { createI18n } from 'vue-i18n-bridge'
136
-
137
- Vue.use(VueI18n , { bridge: true })\n`
138
- const requestObj = {}
139
- const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
140
- i18nKeys.forEach((key) => {
141
- if (i18nObj[`${key}Path`]) {
142
- requestObj[key] = stringifyRequest(i18nObj[`${key}Path`])
143
- delete i18nObj[`${key}Path`]
144
- }
145
- })
146
- content += ` const i18nCfg = ${JSON.stringify(i18nObj)}\n`
147
- Object.keys(requestObj).forEach((key) => {
148
- content += ` i18nCfg.${key} = require(${requestObj[key]})\n`
149
- })
150
- content += ' i18nCfg.legacy = false\n'
151
- content += ` const i18n = createI18n(i18nCfg, VueI18n)
152
- Vue.use(i18n)
153
- Mpx.i18n = i18n
154
- \n`
155
- }
156
- }
43
+ let content = `\n import processComponentOption, { getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
157
44
  let hasApp = true
158
45
  if (!appInfo.name) {
159
46
  hasApp = false
@@ -167,65 +54,10 @@ module.exports = function (script, {
167
54
  content += ` wxsModules.${module} = ${expression}\n`
168
55
  })
169
56
  }
170
- let firstPage = ''
171
- const pagesMap = {}
172
- const componentsMap = {}
173
- Object.keys(localPagesMap).forEach((pagePath) => {
174
- const pageCfg = localPagesMap[pagePath]
175
- const pageRequest = stringifyRequest(pageCfg.resource)
176
- if (tabBarMap && tabBarMap[pagePath]) {
177
- pagesMap[pagePath] = `getComponent(require(${stringifyRequest(tabBarContainerPath)}), { __mpxBuiltIn: true })`
178
- } else {
179
- if (pageCfg.async) {
180
- pagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
181
- } else {
182
- // 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
183
- pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
184
- }
185
- }
186
- if (pagePath === jsonConfig.entryPagePath) {
187
- firstPage = pagePath
188
- }
189
- if (!firstPage && pageCfg.isFirst) {
190
- firstPage = pagePath
191
- }
192
- })
193
-
194
- Object.keys(localComponentsMap).forEach((componentName) => {
195
- const componentCfg = localComponentsMap[componentName]
196
- const componentRequest = stringifyRequest(componentCfg.resource)
197
- if (componentCfg.async) {
198
- componentsMap[componentName] = `()=>import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(res => getComponent(res))`
199
- } else {
200
- componentsMap[componentName] = `getComponent(require(${componentRequest}))`
201
- }
202
- })
203
-
204
- Object.keys(builtInComponentsMap).forEach((componentName) => {
205
- const componentCfg = builtInComponentsMap[componentName]
206
- const componentRequest = stringifyRequest(componentCfg.resource)
207
- componentsMap[componentName] = `getComponent(require(${componentRequest}), { __mpxBuiltIn: true })`
208
- })
209
-
210
- content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
211
- content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
212
- content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
213
- if (!isProduction) {
214
- content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
215
- }
216
-
217
- content += ' /** script content **/\n'
218
57
 
219
- // 传递ctorType以补全js内容
220
- const extraOptions = {
221
- ctorType,
222
- lang: script.lang || 'js'
223
- }
224
- // todo 仅靠vueContentCache保障模块唯一性还是不够严谨,后续需要考虑去除原始query后构建request
225
- content += ` ${getRequire('script', script, extraOptions)}\n`
58
+ // 获取组件集合
59
+ const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext })
226
60
 
227
- // createApp/Page/Component执行完成后立刻获取当前的option并暂存
228
- content += ` const currentOption = global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
229
61
  // 获取pageConfig
230
62
  const pageConfig = {}
231
63
  if (ctorType === 'page') {
@@ -240,40 +72,25 @@ module.exports = function (script, {
240
72
  pageConfig[key] = jsonConfig[key]
241
73
  })
242
74
  }
243
- // 为了执行顺序正确,tabBarPagesMap在app逻辑执行完成后注入,保障小程序中app->page->component的js执行顺序
244
- if (tabBarStr && tabBarPagesMap) {
245
- content += ` global.__tabBar = ${tabBarStr}
246
- Vue.observable(global.__tabBar)
247
- // @ts-ignore
248
- global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
249
- }
250
- // 配置平台转换通过createFactory在core中convertor中定义和进行
251
- // 通过processOption进行组件注册和路由注入
252
- content += ` export default processOption(
253
- currentOption,
254
- ${JSON.stringify(ctorType)},
255
- ${JSON.stringify(firstPage)},
256
- ${JSON.stringify(outputPath)},
257
- ${JSON.stringify(pageConfig)},
258
- // @ts-ignore
259
- ${shallowStringify(pagesMap)},
75
+
76
+ content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction })
77
+ content += getRequireScript({ ctorType, script, loaderContext })
78
+ content += `
79
+ export default processComponentOption({
80
+ option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
81
+ ctorType: ${JSON.stringify(ctorType)},
82
+ outputPath: ${JSON.stringify(outputPath)},
83
+ pageConfig: ${JSON.stringify(pageConfig)},
260
84
  // @ts-ignore
261
- ${shallowStringify(componentsMap)},
262
- ${JSON.stringify(tabBarMap)},
263
- ${JSON.stringify(componentGenerics)},
264
- ${JSON.stringify(genericsInfo)},
265
- getWxsMixin(wxsModules),
266
- ${hasApp}`
267
- if (ctorType === 'app') {
268
- content += `,
269
- Vue,
270
- VueRouter`
271
- }
272
- content += '\n )\n'
85
+ componentsMap: ${shallowStringify(componentsMap)},
86
+ componentGenerics: ${JSON.stringify(componentGenerics)},
87
+ genericsInfo: ${JSON.stringify(genericsInfo)},
88
+ mixin: getWxsMixin(wxsModules),
89
+ hasApp: ${hasApp}
90
+ })\n`
273
91
  return content
274
92
  }
275
93
  })
276
- output += '\n'
277
94
 
278
95
  callback(null, {
279
96
  output
@@ -23,6 +23,7 @@ module.exports = function (template, {
23
23
  decodeHTMLText,
24
24
  externalClasses,
25
25
  checkUsingComponents,
26
+ webConfig,
26
27
  autoVirtualHostRules
27
28
  } = mpx
28
29
  const { resourcePath } = parseRequest(loaderContext.resource)
@@ -32,9 +33,11 @@ module.exports = function (template, {
32
33
  let output = '/* template */\n'
33
34
 
34
35
  if (ctorType === 'app') {
36
+ const { el } = webConfig
37
+ const idName = el?.match(/#(.*)/)?.[1] || 'app'
35
38
  template = {
36
39
  tag: 'template',
37
- content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
40
+ content: `<div id="${idName}"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></div>`
38
41
  }
39
42
  builtInComponentsMap['mpx-keep-alive'] = {
40
43
  resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
@@ -0,0 +1,202 @@
1
+ const hasOwn = require('../utils/has-own')
2
+ const loaderUtils = require('loader-utils')
3
+ const normalize = require('../utils/normalize')
4
+ const createHelpers = require('../helpers')
5
+ const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
6
+ const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
7
+ const addQuery = require('../utils/add-query')
8
+
9
+ function stringifyRequest (loaderContext, request) {
10
+ return loaderUtils.stringifyRequest(loaderContext, request)
11
+ }
12
+
13
+ function shallowStringify (obj) {
14
+ const arr = []
15
+ for (const key in obj) {
16
+ if (hasOwn(obj, key)) {
17
+ let value = obj[key]
18
+ if (Array.isArray(value)) {
19
+ value = `[${value.join(',')}]`
20
+ }
21
+ arr.push(`'${key}':${value}`)
22
+ }
23
+ }
24
+ return `{${arr.join(',')}}`
25
+ }
26
+
27
+ function getAsyncChunkName (chunkName) {
28
+ if (chunkName && typeof chunkName !== 'boolean') {
29
+ return `/* webpackChunkName: "${chunkName}" */`
30
+ }
31
+ return ''
32
+ }
33
+
34
+ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext }) {
35
+ const componentsMap = {}
36
+ if (localComponentsMap) {
37
+ Object.keys(localComponentsMap).forEach((componentName) => {
38
+ const componentCfg = localComponentsMap[componentName]
39
+ const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
40
+ if (componentCfg.async) {
41
+ componentsMap[componentName] = `()=>import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(res => getComponent(res))`
42
+ } else {
43
+ componentsMap[componentName] = `getComponent(require(${componentRequest}))`
44
+ }
45
+ })
46
+ }
47
+ if (builtInComponentsMap) {
48
+ Object.keys(builtInComponentsMap).forEach((componentName) => {
49
+ const componentCfg = builtInComponentsMap[componentName]
50
+ const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
51
+ componentsMap[componentName] = `getComponent(require(${componentRequest}), { __mpxBuiltIn: true })`
52
+ })
53
+ }
54
+ return componentsMap
55
+ }
56
+
57
+ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBarStr, jsonConfig }) {
58
+ let globalTabBar = ''
59
+ let firstPage = ''
60
+ const pagesMap = {}
61
+ const tabBarPagesMap = {}
62
+ if (tabBar && tabBarMap) {
63
+ // 挂载tabBar组件
64
+ const tabBarRequest = stringifyRequest(loaderContext, addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
65
+ tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
66
+ // 挂载tabBar页面
67
+ Object.keys(tabBarMap).forEach((pagePath) => {
68
+ const pageCfg = localPagesMap[pagePath]
69
+ if (pageCfg) {
70
+ const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
71
+ if (pageCfg.async) {
72
+ tabBarPagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
73
+ } else {
74
+ tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
75
+ }
76
+ } else {
77
+ loaderContext.emitWarning(
78
+ new Error('[json processor][' + loaderContext.resource + ']: ' + `TabBar page path ${pagePath} is not exist in local page map, please check!`)
79
+ )
80
+ }
81
+ })
82
+ }
83
+ if (tabBarStr && tabBarPagesMap) {
84
+ globalTabBar += `
85
+ global.__tabBar = ${tabBarStr}
86
+ Vue.observable(global.__tabBar)
87
+ // @ts-ignore
88
+ global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
89
+ }
90
+ Object.keys(localPagesMap).forEach((pagePath) => {
91
+ const pageCfg = localPagesMap[pagePath]
92
+ const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
93
+ if (tabBarMap && tabBarMap[pagePath]) {
94
+ pagesMap[pagePath] = `getComponent(require(${stringifyRequest(loaderContext, tabBarContainerPath)}), { __mpxBuiltIn: true })`
95
+ } else {
96
+ if (pageCfg.async) {
97
+ pagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
98
+ } else {
99
+ // 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
100
+ pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
101
+ }
102
+ }
103
+
104
+ if (pagePath === jsonConfig.entryPagePath) {
105
+ firstPage = pagePath
106
+ }
107
+ if (!firstPage && pageCfg.isFirst) {
108
+ firstPage = pagePath
109
+ }
110
+ })
111
+ return {
112
+ pagesMap,
113
+ firstPage,
114
+ globalTabBar
115
+ }
116
+ }
117
+
118
+ function getRequireScript ({ ctorType, script, loaderContext }) {
119
+ let content = ' /** script content **/\n'
120
+ const extraOptions = { ctorType, lang: script.lang || 'js' }
121
+ const { getRequire } = createHelpers(loaderContext)
122
+ content += ` ${getRequire('script', script, extraOptions)}\n`
123
+ return content
124
+ }
125
+
126
+ function buildGlobalParams ({ moduleId, scriptSrcMode, loaderContext, isProduction, jsonConfig, webConfig, isMain, globalTabBar }) {
127
+ let content = ''
128
+ if (isMain) {
129
+ content += `
130
+ global.getApp = function(){}
131
+ global.getCurrentPages = function () {
132
+ if (!(typeof window !== 'undefined')) {
133
+ console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
134
+ }
135
+ const router = global.__mpxRouter
136
+ if(!router) return []
137
+ // @ts-ignore
138
+ return (router.lastStack || router.stack).map(item => {
139
+ let page
140
+ const vnode = item.vnode
141
+ if (vnode && vnode.componentInstance) {
142
+ page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
143
+ }
144
+ return page || { route: item.path.slice(1) }
145
+ })
146
+ }
147
+ global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
148
+ global.__mpxGenericsMap = {}
149
+ global.__mpxOptionsMap = {}
150
+ global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
151
+ global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
152
+ global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
153
+ if (globalTabBar) {
154
+ content += globalTabBar
155
+ }
156
+ }
157
+ content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
158
+ content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
159
+ content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
160
+ if (!isProduction) {
161
+ content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
162
+ }
163
+ return content
164
+ }
165
+
166
+ function buildI18n ({ i18n, loaderContext }) {
167
+ let i18nContent = ''
168
+ const i18nObj = Object.assign({}, i18n)
169
+ i18nContent += `
170
+ import VueI18n from 'vue-i18n'
171
+ import { createI18n } from 'vue-i18n-bridge'
172
+ Vue.use(VueI18n , { bridge: true })\n`
173
+ const requestObj = {}
174
+ const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
175
+ i18nKeys.forEach((key) => {
176
+ if (i18nObj[`${key}Path`]) {
177
+ requestObj[key] = stringifyRequest(loaderContext, i18nObj[`${key}Path`])
178
+ delete i18nObj[`${key}Path`]
179
+ }
180
+ })
181
+ i18nContent += ` const i18nCfg = ${JSON.stringify(i18nObj)}\n`
182
+ Object.keys(requestObj).forEach((key) => {
183
+ i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
184
+ })
185
+ i18nContent += `
186
+ i18nCfg.legacy = false
187
+ const i18n = createI18n(i18nCfg, VueI18n)
188
+ Vue.use(i18n)
189
+ Mpx.i18n = i18n\n`
190
+ return i18nContent
191
+ }
192
+
193
+ module.exports = {
194
+ buildPagesMap,
195
+ buildComponentsMap,
196
+ getRequireScript,
197
+ buildGlobalParams,
198
+ shallowStringify,
199
+ getAsyncChunkName,
200
+ stringifyRequest,
201
+ buildI18n
202
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.40-test",
3
+ "version": "2.8.40-test.2",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
7
7
  ],
8
8
  "author": "donghongping",
9
- "license": "Apache",
9
+ "license": "Apache-2.0",
10
10
  "main": "lib/index.js",
11
11
  "directories": {
12
12
  "lib": "lib"
@@ -54,11 +54,12 @@
54
54
  "postcss-modules-values": "^4.0.0",
55
55
  "postcss-selector-parser": "^6.0.8",
56
56
  "postcss-value-parser": "^4.0.2",
57
+ "semver": "^7.5.4",
57
58
  "source-list-map": "^2.0.0",
58
59
  "video.js": "^8.6.0"
59
60
  },
60
61
  "peerDependencies": {
61
- "webpack": "^5.48.0"
62
+ "webpack": "^5.75.0"
62
63
  },
63
64
  "publishConfig": {
64
65
  "registry": "https://registry.npmjs.org",
@@ -82,5 +83,5 @@
82
83
  "engines": {
83
84
  "node": ">=14.14.0"
84
85
  },
85
- "gitHead": "8524f9b69ebcfb0667ebff2608cf6f675f14f141"
86
+ "gitHead": "7b1911025a2eb47eddc046775f17b6f1405fdd54"
86
87
  }
@@ -1,17 +0,0 @@
1
- const { isOriginTag, isBuildInTag } = require('../../../../utils/dom-tag-config')
2
-
3
- module.exports = function () {
4
- return {
5
- waterfall: true,
6
- test: (input) => isOriginTag(input) || isBuildInTag(input),
7
- // 处理原生tag
8
- web (tag, data = {}) {
9
- // @see packages/webpack-plugin/lib/platform/json/wx/index.js webHTMLTagProcesser
10
- const newTag = `mpx-com-${tag}`
11
- const usingComponents = data.usingComponents || []
12
- // 存在同名组件,则返回新tag
13
- if (usingComponents.includes(newTag)) return newTag
14
- return tag
15
- }
16
- }
17
- }
@@ -1,15 +0,0 @@
1
-
2
- module.exports = (opts) => {
3
- return {
4
- postcssPlugin: 'trim',
5
- Once: (root) => {
6
- root.walk(({ type, raws }) => {
7
- if (type === 'rule' || type === 'atrule') {
8
- raws.before = raws.after = '\n'
9
- }
10
- })
11
- }
12
- }
13
- }
14
-
15
- module.exports.postcss = true