@mpxjs/webpack-plugin 2.7.1-beta.0 → 2.7.1-beta.4
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.
- package/lib/helpers.js +4 -3
- package/lib/independent-loader.js +3 -10
- package/lib/index.js +70 -12
- package/lib/json-compiler/index.js +1 -3
- package/lib/loader.js +23 -18
- package/lib/native-loader.js +4 -3
- package/lib/runtime/components/web/mpx-swiper.vue +19 -5
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/style-compiler/index.js +2 -1
- package/lib/style-compiler/plugins/vw.js +5 -4
- package/lib/web/processScript.js +2 -2
- package/lib/wxs/i18n-loader.js +4 -1
- package/lib/wxs/pre-loader.js +6 -1
- package/package.json +5 -2
package/lib/helpers.js
CHANGED
|
@@ -14,6 +14,7 @@ const defaultLang = {
|
|
|
14
14
|
|
|
15
15
|
module.exports = function createHelpers (loaderContext) {
|
|
16
16
|
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
17
18
|
|
|
18
19
|
function getRequire (type, part, extraOptions, index) {
|
|
19
20
|
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
@@ -35,9 +36,9 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
35
36
|
|
|
36
37
|
function getFakeRequest (type, part) {
|
|
37
38
|
const lang = part.lang || defaultLang[type] || type
|
|
38
|
-
const {
|
|
39
|
-
if (lang === 'json')
|
|
40
|
-
return addQuery(`${resourcePath}.${lang}`,
|
|
39
|
+
const options = { ...queryObj }
|
|
40
|
+
if (lang === 'json') options.asScript = true
|
|
41
|
+
return addQuery(`${resourcePath}.${lang}`, options)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function getRequestString (type, part, extraOptions = {}, index = 0) {
|
|
@@ -40,16 +40,9 @@ module.exports = function (content) {
|
|
|
40
40
|
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
41
41
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
42
42
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
output += `if (!global.i18n) {
|
|
47
|
-
global.i18n = ${JSON.stringify({
|
|
48
|
-
locale: i18n.locale,
|
|
49
|
-
version: 0
|
|
50
|
-
})}
|
|
51
|
-
global.i18nMethods = ${i18nMethodsVar}
|
|
52
|
-
}\n`
|
|
43
|
+
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
44
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
45
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
53
46
|
}
|
|
54
47
|
output += content
|
|
55
48
|
output += '\n'
|
package/lib/index.js
CHANGED
|
@@ -139,9 +139,6 @@ class MpxWebpackPlugin {
|
|
|
139
139
|
options.transRpxRules = options.transRpxRules || null
|
|
140
140
|
options.auditResource = options.auditResource || false
|
|
141
141
|
options.decodeHTMLText = options.decodeHTMLText || false
|
|
142
|
-
options.nativeOptions = Object.assign({
|
|
143
|
-
cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
|
|
144
|
-
}, options.nativeOptions)
|
|
145
142
|
options.i18n = options.i18n || null
|
|
146
143
|
options.checkUsingComponents = options.checkUsingComponents || false
|
|
147
144
|
options.reportSize = options.reportSize || null
|
|
@@ -156,6 +153,10 @@ class MpxWebpackPlugin {
|
|
|
156
153
|
include: () => true
|
|
157
154
|
}
|
|
158
155
|
options.customOutputPath = options.customOutputPath || null
|
|
156
|
+
options.nativeConfig = Object.assign({
|
|
157
|
+
cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
|
|
158
|
+
}, options.nativeConfig)
|
|
159
|
+
options.webConfig = options.webConfig || {}
|
|
159
160
|
this.options = options
|
|
160
161
|
}
|
|
161
162
|
|
|
@@ -315,6 +316,7 @@ class MpxWebpackPlugin {
|
|
|
315
316
|
originalWriteFile(filePath, content, callback)
|
|
316
317
|
}
|
|
317
318
|
}
|
|
319
|
+
|
|
318
320
|
const defs = this.options.defs
|
|
319
321
|
|
|
320
322
|
const typeExtMap = config[this.options.mode].typeExtMap
|
|
@@ -485,13 +487,13 @@ class MpxWebpackPlugin {
|
|
|
485
487
|
exportModules: new Set(),
|
|
486
488
|
// 记录entryModule与entryNode的对应关系,用于体积分析
|
|
487
489
|
entryNodeModulesMap: new Map(),
|
|
488
|
-
|
|
490
|
+
// 记录与asset相关联的modules,用于体积分析
|
|
491
|
+
assetModulesMap: new Map(),
|
|
489
492
|
usingComponents: {},
|
|
490
493
|
// todo es6 map读写性能高于object,之后会逐步替换
|
|
491
494
|
vueContentCache: new Map(),
|
|
492
495
|
currentPackageRoot: '',
|
|
493
496
|
wxsContentMap: {},
|
|
494
|
-
assetsInfo: new Map(),
|
|
495
497
|
forceUsePageCtor: this.options.forceUsePageCtor,
|
|
496
498
|
resolveMode: this.options.resolveMode,
|
|
497
499
|
mode: this.options.mode,
|
|
@@ -504,8 +506,10 @@ class MpxWebpackPlugin {
|
|
|
504
506
|
transRpxRules: this.options.transRpxRules,
|
|
505
507
|
postcssInlineConfig: this.options.postcssInlineConfig,
|
|
506
508
|
decodeHTMLText: this.options.decodeHTMLText,
|
|
507
|
-
// native
|
|
508
|
-
|
|
509
|
+
// native文件专用配置
|
|
510
|
+
nativeConfig: this.options.nativeConfig,
|
|
511
|
+
// 输出web专用配置
|
|
512
|
+
webConfig: this.options.webConfig,
|
|
509
513
|
tabBarMap: {},
|
|
510
514
|
defs: preProcessDefs(this.options.defs),
|
|
511
515
|
i18n: this.options.i18n,
|
|
@@ -788,6 +792,12 @@ class MpxWebpackPlugin {
|
|
|
788
792
|
return source
|
|
789
793
|
})
|
|
790
794
|
|
|
795
|
+
compilation.hooks.moduleAsset.tap('MpxWebpackPlugin', (module, filename) => {
|
|
796
|
+
const modules = mpx.assetModulesMap.get(filename) || new Set()
|
|
797
|
+
modules.add(module)
|
|
798
|
+
mpx.assetModulesMap.set(filename, modules)
|
|
799
|
+
})
|
|
800
|
+
|
|
791
801
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
|
792
802
|
const extractedAssetsMap = new Map()
|
|
793
803
|
for (const module of compilation.modules) {
|
|
@@ -800,8 +810,7 @@ class MpxWebpackPlugin {
|
|
|
800
810
|
extractedAssetsMap.set(filename, extractedAssets)
|
|
801
811
|
}
|
|
802
812
|
extractedAssets.push(extractedInfo)
|
|
803
|
-
|
|
804
|
-
// compilation.hooks.moduleAsset.call(module, filename)
|
|
813
|
+
compilation.hooks.moduleAsset.call(module, filename)
|
|
805
814
|
}
|
|
806
815
|
}
|
|
807
816
|
}
|
|
@@ -1028,7 +1037,6 @@ class MpxWebpackPlugin {
|
|
|
1028
1037
|
}
|
|
1029
1038
|
|
|
1030
1039
|
const processedChunk = new Set()
|
|
1031
|
-
// const rootName = compilation.entries.keys().next().value
|
|
1032
1040
|
const appName = mpx.appInfo.name
|
|
1033
1041
|
|
|
1034
1042
|
function processChunk (chunk, isRuntime, relativeChunks) {
|
|
@@ -1273,7 +1281,7 @@ try {
|
|
|
1273
1281
|
})
|
|
1274
1282
|
})
|
|
1275
1283
|
|
|
1276
|
-
compiler.hooks.emit.
|
|
1284
|
+
compiler.hooks.emit.tap('MpxWebpackPlugin', (compilation) => {
|
|
1277
1285
|
if (this.options.generateBuildMap) {
|
|
1278
1286
|
const pagesMap = compilation.__mpx__.pagesMap
|
|
1279
1287
|
const componentsPackageMap = compilation.__mpx__.componentsMap
|
|
@@ -1290,7 +1298,57 @@ try {
|
|
|
1290
1298
|
}
|
|
1291
1299
|
}
|
|
1292
1300
|
}
|
|
1293
|
-
|
|
1301
|
+
})
|
|
1302
|
+
|
|
1303
|
+
const clearFileCache = () => {
|
|
1304
|
+
const fs = compiler.intermediateFileSystem
|
|
1305
|
+
const cacheLocation = compiler.options.cache.cacheLocation
|
|
1306
|
+
return new Promise((resolve) => {
|
|
1307
|
+
if (typeof fs.rm === 'function') {
|
|
1308
|
+
fs.rm(cacheLocation, {
|
|
1309
|
+
recursive: true,
|
|
1310
|
+
force: true
|
|
1311
|
+
}, resolve)
|
|
1312
|
+
} else {
|
|
1313
|
+
// polyfill fs.rm
|
|
1314
|
+
const rm = (file, callback) => {
|
|
1315
|
+
async.waterfall([
|
|
1316
|
+
(callback) => {
|
|
1317
|
+
fs.stat(file, callback)
|
|
1318
|
+
},
|
|
1319
|
+
(stats, callback) => {
|
|
1320
|
+
if (stats.isDirectory()) {
|
|
1321
|
+
const dir = file
|
|
1322
|
+
fs.readdir(dir, (err, files) => {
|
|
1323
|
+
if (err) return callback(err)
|
|
1324
|
+
async.each(files, (file, callback) => {
|
|
1325
|
+
file = path.join(dir, file)
|
|
1326
|
+
rm(file, callback)
|
|
1327
|
+
}, (err) => {
|
|
1328
|
+
if (err) return callback(err)
|
|
1329
|
+
fs.rmdir(dir, callback)
|
|
1330
|
+
})
|
|
1331
|
+
})
|
|
1332
|
+
} else {
|
|
1333
|
+
fs.unlink(file, callback)
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
], callback)
|
|
1337
|
+
}
|
|
1338
|
+
rm(cacheLocation, resolve)
|
|
1339
|
+
}
|
|
1340
|
+
})
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
compiler.hooks.done.tapPromise('MpxWebpackPlugin', async () => {
|
|
1344
|
+
const cache = compiler.getCache('MpxWebpackPlugin')
|
|
1345
|
+
const cacheIsValid = await cache.getPromise('cacheIsValid', null)
|
|
1346
|
+
if (!cacheIsValid) {
|
|
1347
|
+
await Promise.all([
|
|
1348
|
+
clearFileCache(),
|
|
1349
|
+
cache.storePromise('cacheIsValid', null, true)
|
|
1350
|
+
])
|
|
1351
|
+
}
|
|
1294
1352
|
})
|
|
1295
1353
|
}
|
|
1296
1354
|
}
|
|
@@ -272,9 +272,7 @@ module.exports = function (content) {
|
|
|
272
272
|
env
|
|
273
273
|
})
|
|
274
274
|
// 对于通过.mpx文件声明的独立分包,默认将其自身的script block视为init module
|
|
275
|
-
if (
|
|
276
|
-
queryObj.independent = result
|
|
277
|
-
}
|
|
275
|
+
if (queryObj.independent === true) queryObj.independent = result
|
|
278
276
|
getJSONContent(parts.json || {}, this, (err, content) => {
|
|
279
277
|
callback(err, result, content)
|
|
280
278
|
})
|
package/lib/loader.js
CHANGED
|
@@ -224,16 +224,9 @@ module.exports = function (content) {
|
|
|
224
224
|
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
225
225
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
226
226
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
output += `if (!global.i18n) {
|
|
231
|
-
global.i18n = ${JSON.stringify({
|
|
232
|
-
locale: i18n.locale,
|
|
233
|
-
version: 0
|
|
234
|
-
})}
|
|
235
|
-
global.i18nMethods = ${i18nMethodsVar}
|
|
236
|
-
}\n`
|
|
227
|
+
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
228
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
229
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
237
230
|
}
|
|
238
231
|
|
|
239
232
|
// 为独立分包注入init module
|
|
@@ -241,6 +234,8 @@ module.exports = function (content) {
|
|
|
241
234
|
const independentLoader = normalize.lib('independent-loader.js')
|
|
242
235
|
const independentInitRequest = `!!${independentLoader}!${independent}`
|
|
243
236
|
this._module.addDependency(new CommonJsVariableDependency(independentInitRequest))
|
|
237
|
+
// 避免该模块被concatenate导致注入的independent init没有最先执行
|
|
238
|
+
this._module.buildInfo.moduleConcatenationBailout = 'independent init'
|
|
244
239
|
}
|
|
245
240
|
|
|
246
241
|
// 注入构造函数
|
|
@@ -267,6 +262,10 @@ module.exports = function (content) {
|
|
|
267
262
|
|
|
268
263
|
if (template) {
|
|
269
264
|
const extraOptions = {
|
|
265
|
+
...template.src ? {
|
|
266
|
+
...queryObj,
|
|
267
|
+
resourcePath
|
|
268
|
+
} : null,
|
|
270
269
|
hasScoped,
|
|
271
270
|
hasComment,
|
|
272
271
|
isNative,
|
|
@@ -287,16 +286,16 @@ module.exports = function (content) {
|
|
|
287
286
|
parts.styles.forEach((style, i) => {
|
|
288
287
|
const scoped = style.scoped || autoScope
|
|
289
288
|
const extraOptions = {
|
|
289
|
+
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
290
|
+
...style.src ? {
|
|
291
|
+
...queryObj,
|
|
292
|
+
isStatic: true,
|
|
293
|
+
issuerFile: mpx.getExtractedFile(addQuery(this.resource, { type: 'styles' }, true))
|
|
294
|
+
} : null,
|
|
290
295
|
moduleId,
|
|
291
296
|
scoped
|
|
292
297
|
}
|
|
293
298
|
// require style
|
|
294
|
-
if (style.src) {
|
|
295
|
-
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
296
|
-
extraOptions.isStatic = true
|
|
297
|
-
const issuerResource = addQuery(this.resource, { type: 'styles' }, true)
|
|
298
|
-
extraOptions.issuerFile = mpx.getExtractedFile(issuerResource)
|
|
299
|
-
}
|
|
300
299
|
output += getRequire('styles', style, extraOptions, i) + '\n'
|
|
301
300
|
})
|
|
302
301
|
} else if (ctorType === 'app' && mode === 'ali') {
|
|
@@ -307,7 +306,10 @@ module.exports = function (content) {
|
|
|
307
306
|
output += '/* json */\n'
|
|
308
307
|
// 给予json默认值, 确保生成json request以自动补全json
|
|
309
308
|
const json = parts.json || {}
|
|
310
|
-
output += getRequire('json', json, json.src && {
|
|
309
|
+
output += getRequire('json', json, json.src && {
|
|
310
|
+
...queryObj,
|
|
311
|
+
resourcePath
|
|
312
|
+
}) + '\n'
|
|
311
313
|
|
|
312
314
|
// script
|
|
313
315
|
output += '/* script */\n'
|
|
@@ -319,9 +321,12 @@ module.exports = function (content) {
|
|
|
319
321
|
if (scriptSrcMode) output += `global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
|
|
320
322
|
// 传递ctorType以补全js内容
|
|
321
323
|
const extraOptions = {
|
|
324
|
+
...script.src ? {
|
|
325
|
+
...queryObj,
|
|
326
|
+
resourcePath
|
|
327
|
+
} : null,
|
|
322
328
|
ctorType
|
|
323
329
|
}
|
|
324
|
-
if (script.src) extraOptions.resourcePath = resourcePath
|
|
325
330
|
output += getRequire('script', script, extraOptions) + '\n'
|
|
326
331
|
}
|
|
327
332
|
callback(null, output)
|
package/lib/native-loader.js
CHANGED
|
@@ -55,7 +55,7 @@ module.exports = function (content) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function checkCSSLangFiles (callback) {
|
|
58
|
-
const langs = mpx.
|
|
58
|
+
const langs = mpx.nativeConfig.cssLangs || ['less', 'stylus', 'scss', 'sass']
|
|
59
59
|
const results = []
|
|
60
60
|
async.eachOf(langs, function (lang, i, callback) {
|
|
61
61
|
if (!CSS_LANG_EXT_MAP[lang]) {
|
|
@@ -137,9 +137,10 @@ module.exports = function (content) {
|
|
|
137
137
|
const getRequireByType = (type) => {
|
|
138
138
|
const src = typeResourceMap[type]
|
|
139
139
|
const part = { src }
|
|
140
|
-
const extraOptions =
|
|
140
|
+
const extraOptions = {
|
|
141
|
+
...queryObj,
|
|
141
142
|
resourcePath
|
|
142
|
-
}
|
|
143
|
+
}
|
|
143
144
|
|
|
144
145
|
switch (type) {
|
|
145
146
|
case 'template':
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
easingFunction: {
|
|
37
37
|
type: String,
|
|
38
38
|
default: 'default'
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
scrollOptions: Object
|
|
40
41
|
},
|
|
41
42
|
data () {
|
|
42
43
|
return {
|
|
@@ -90,11 +91,21 @@
|
|
|
90
91
|
this.goto(val)
|
|
91
92
|
}
|
|
92
93
|
},
|
|
94
|
+
activated () {
|
|
95
|
+
if (this.bs && this.autoplay) {
|
|
96
|
+
this.bs.startPlay()
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
deactivated () {
|
|
100
|
+
if (this.bs && this.autoplay) {
|
|
101
|
+
this.bs.pausePlay()
|
|
102
|
+
}
|
|
103
|
+
},
|
|
93
104
|
beforeCreate () {
|
|
94
105
|
this.itemIds = []
|
|
95
106
|
},
|
|
96
107
|
mounted () {
|
|
97
|
-
|
|
108
|
+
const originBsOptions = {
|
|
98
109
|
scrollX: !this.vertical,
|
|
99
110
|
scrollY: this.vertical,
|
|
100
111
|
slide: {
|
|
@@ -103,14 +114,17 @@
|
|
|
103
114
|
speed: this.duration,
|
|
104
115
|
easing: this.easing,
|
|
105
116
|
interval: this.interval,
|
|
106
|
-
autoplay: this.autoplay
|
|
117
|
+
autoplay: this.autoplay,
|
|
118
|
+
startPageXIndex: this.vertical ? 0 : this.current,
|
|
119
|
+
startPageYIndex: this.vertical? this.current : 0
|
|
107
120
|
},
|
|
108
121
|
momentum: false,
|
|
109
122
|
bounce: false,
|
|
110
123
|
probeType: 3,
|
|
111
124
|
stopPropagation: true
|
|
112
|
-
}
|
|
113
|
-
|
|
125
|
+
}
|
|
126
|
+
const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
|
|
127
|
+
this.bs = new BScroll(this.$refs.wrapper, bsOptions)
|
|
114
128
|
this.bs.on('slideWillChange', (page) => {
|
|
115
129
|
this.currentIndex = this.vertical ? page.pageY : page.pageX
|
|
116
130
|
this.$emit('change', getCustomEvent('change', {
|
package/lib/runtime/i18n.wxs
CHANGED
|
@@ -6,7 +6,6 @@ function genRegExp (str, flags) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
function likeArray (arr) {
|
|
11
10
|
if (!__mpx_wxs__) {
|
|
12
11
|
return Array.isArray(arr)
|
|
@@ -23,7 +22,6 @@ function isDef (v) {
|
|
|
23
22
|
return v !== undefined && v !== null
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
25
|
var RE_TOKEN_LIST_VALUE = genRegExp('^[0-9]+')
|
|
28
26
|
var RE_TOKEN_NAMED_VALUE = genRegExp('^[A-Za-z0-9_]+')
|
|
29
27
|
|
|
@@ -40,7 +38,10 @@ function parseMessage (format) {
|
|
|
40
38
|
var char = format[position++]
|
|
41
39
|
if (char === '{') {
|
|
42
40
|
if (text) {
|
|
43
|
-
tokens.push({
|
|
41
|
+
tokens.push({
|
|
42
|
+
type: 'text',
|
|
43
|
+
value: text
|
|
44
|
+
})
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
text = ''
|
|
@@ -56,7 +57,10 @@ function parseMessage (format) {
|
|
|
56
57
|
: isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
|
|
57
58
|
? 'named'
|
|
58
59
|
: 'unknown'
|
|
59
|
-
tokens.push({
|
|
60
|
+
tokens.push({
|
|
61
|
+
value: sub,
|
|
62
|
+
type: type
|
|
63
|
+
})
|
|
60
64
|
} else if (char === '%') {
|
|
61
65
|
// when found rails i18n syntax, skip text capture
|
|
62
66
|
if (format[(position)] !== '{') {
|
|
@@ -67,7 +71,10 @@ function parseMessage (format) {
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
text && tokens.push({
|
|
74
|
+
text && tokens.push({
|
|
75
|
+
type: 'text',
|
|
76
|
+
value: text
|
|
77
|
+
})
|
|
71
78
|
|
|
72
79
|
return tokens
|
|
73
80
|
}
|
|
@@ -263,6 +270,11 @@ function exist (messages, locale, key) {
|
|
|
263
270
|
var messages = {}
|
|
264
271
|
var dateTimeFormats = {}
|
|
265
272
|
var numberFormats = {}
|
|
273
|
+
var locale = 'zh-CN'
|
|
274
|
+
|
|
275
|
+
function getLocale () {
|
|
276
|
+
return __mpx_locale__ || locale
|
|
277
|
+
}
|
|
266
278
|
|
|
267
279
|
function getMessages () {
|
|
268
280
|
// __mpx_messages__会在编译时通过lib/wxs/i18n-loader注入
|
|
@@ -339,7 +351,15 @@ module.exports = {
|
|
|
339
351
|
}
|
|
340
352
|
|
|
341
353
|
if (!__mpx_wxs__) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
354
|
+
if (!global.i18n) {
|
|
355
|
+
global.i18n = {
|
|
356
|
+
locale: getLocale(),
|
|
357
|
+
version: 0
|
|
358
|
+
}
|
|
359
|
+
global.i18nMethods = Object.assign(module.exports, {
|
|
360
|
+
__getMessages: getMessages,
|
|
361
|
+
__getDateTimeFormats: getDateTimeFormats,
|
|
362
|
+
__getNumberFormats: getNumberFormats
|
|
363
|
+
})
|
|
364
|
+
}
|
|
345
365
|
}
|
|
@@ -23,6 +23,7 @@ module.exports = function (css, map) {
|
|
|
23
23
|
const transRpxRulesRaw = mpx.transRpxRules
|
|
24
24
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
25
25
|
|
|
26
|
+
const transRpxFn = mpx.webConfig.transRpxFn
|
|
26
27
|
const testResolveRange = (include = () => true, exclude) => {
|
|
27
28
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
28
29
|
}
|
|
@@ -67,7 +68,7 @@ module.exports = function (css, map) {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if (mpx.mode === 'web') {
|
|
70
|
-
plugins.push(vw)
|
|
71
|
+
plugins.push(vw({ transRpxFn }))
|
|
71
72
|
}
|
|
72
73
|
// source map
|
|
73
74
|
if (this.sourceMap && !options.map) {
|
|
@@ -5,12 +5,13 @@ const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
|
5
5
|
module.exports = postcss.plugin('vw', (options = {}) => root => {
|
|
6
6
|
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
7
7
|
|
|
8
|
+
const transRpxFn = options.transRpxFn && typeof options.transRpxFn === 'function' ? options.transRpxFn : function (match, $1) {
|
|
9
|
+
if ($1 === '0') return $1
|
|
10
|
+
return `${$1 * rpx2vwRatio}vw`
|
|
11
|
+
}
|
|
8
12
|
function transVw (declaration) {
|
|
9
13
|
if (rpxRegExp.test(declaration.value)) {
|
|
10
|
-
declaration.value = declaration.value.replace(rpxRegExpG,
|
|
11
|
-
if ($1 === '0') return $1
|
|
12
|
-
return `${$1 * rpx2vwRatio}vw`
|
|
13
|
-
})
|
|
14
|
+
declaration.value = declaration.value.replace(rpxRegExpG, transRpxFn)
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
package/lib/web/processScript.js
CHANGED
|
@@ -210,11 +210,11 @@ module.exports = function (script, {
|
|
|
210
210
|
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
211
211
|
}
|
|
212
212
|
// 为了正确获取currentSrcMode便于运行时进行转换,对于src引入的组件script采用require方式引入(由于webpack会将import的执行顺序上升至最顶),这意味着对于src引入脚本中的named export将不会生效,不过鉴于mpx和小程序中本身也没有在组件script中声明export的用法,所以应该没有影响
|
|
213
|
-
content += '\n\n\n/**
|
|
213
|
+
content += '\n\n\n/** Source start **/\n'
|
|
214
214
|
content += script.src
|
|
215
215
|
? `require(${stringifyRequest(script.src)})\n`
|
|
216
216
|
: script.content
|
|
217
|
-
content += '\n/**
|
|
217
|
+
content += '\n/** Source end **/\n\n\n'
|
|
218
218
|
// createApp/Page/Component执行完成后立刻获取当前的option并暂存
|
|
219
219
|
content += ` const currentOption = global.currentOption\n`
|
|
220
220
|
// 获取pageConfig
|
package/lib/wxs/i18n-loader.js
CHANGED
|
@@ -3,7 +3,7 @@ const loaderUtils = require('loader-utils')
|
|
|
3
3
|
|
|
4
4
|
module.exports = function (content) {
|
|
5
5
|
const i18n = this.getMpx().i18n
|
|
6
|
-
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__\n'
|
|
6
|
+
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__, __mpx_locale__\n'
|
|
7
7
|
if (i18n) {
|
|
8
8
|
if (i18n.messages) {
|
|
9
9
|
prefix += `__mpx_messages__ = ${JSON.stringify(i18n.messages)}\n`
|
|
@@ -20,6 +20,9 @@ module.exports = function (content) {
|
|
|
20
20
|
} else if (i18n.numberFormatsPath) {
|
|
21
21
|
prefix += `__mpx_number_formats__ = require(${loaderUtils.stringifyRequest(this, i18n.numberFormatsPath)})\n`
|
|
22
22
|
}
|
|
23
|
+
if (i18n.locale) {
|
|
24
|
+
prefix += `__mpx_locale__ = ${JSON.stringify(i18n.locale)}\n`
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
content = prefix + content
|
|
25
28
|
return content
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -39,11 +39,16 @@ module.exports = function (content) {
|
|
|
39
39
|
let results = targetPath.unshiftContainer('body', insertNodes) || []
|
|
40
40
|
targetPath.inserted = true
|
|
41
41
|
results.forEach((item) => {
|
|
42
|
-
item.
|
|
42
|
+
item.shouldStopTraverse = true
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
ForStatement (path) {
|
|
48
|
+
if (path.shouldStopTraverse) {
|
|
49
|
+
path.stop()
|
|
50
|
+
}
|
|
51
|
+
},
|
|
47
52
|
// 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
|
|
48
53
|
ExportNamedDeclaration (path) {
|
|
49
54
|
if (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.1-beta.
|
|
3
|
+
"version": "2.7.1-beta.4",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -77,5 +77,8 @@
|
|
|
77
77
|
"@types/babel-traverse": "^6.25.4",
|
|
78
78
|
"@types/babel-types": "^7.0.4"
|
|
79
79
|
},
|
|
80
|
-
"
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=14.14.0"
|
|
82
|
+
},
|
|
83
|
+
"gitHead": "bb23a30c136854abc94e9b31a36b0857a00e45d4"
|
|
81
84
|
}
|