@mpxjs/webpack-plugin 2.6.109 → 2.6.113
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/index.js +11 -10
- package/lib/loader.js +11 -4
- package/lib/runtime/components/web/mpx-swiper.vue +19 -5
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/stringify.wxs +3 -1
- package/lib/style-compiler/index.js +2 -1
- package/lib/style-compiler/plugins/vw.js +5 -4
- package/lib/template-compiler/compiler.js +3 -1
- package/lib/template-compiler/trans-dynamic-class-expr.js +25 -20
- package/lib/web/processScript.js +0 -6
- package/lib/wxs/wxs-pre-loader.js +6 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -363,10 +363,12 @@ class MpxWebpackPlugin {
|
|
|
363
363
|
compilation.errors.push(e)
|
|
364
364
|
}
|
|
365
365
|
})
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
366
|
+
const queryObj = {}
|
|
367
|
+
if (packageRoot) queryObj.packageRoot = packageRoot
|
|
368
|
+
// todo 后续可以考虑用module.layer来隔离独立分包的模块
|
|
369
|
+
if (isIndependent) queryObj.isIndependent = true
|
|
370
|
+
module.request = addQuery(module.request, queryObj)
|
|
371
|
+
module.resource = addQuery(module.resource, queryObj)
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
374
|
|
|
@@ -413,6 +415,7 @@ class MpxWebpackPlugin {
|
|
|
413
415
|
// 当前机制下分包处理队列在app.json的json-compiler中进行,由于addEntry回调特性,无法保障app.js中引用的模块都被标记为主包,故重写processModuleDependencies获取app.js及其所有依赖处理完成的时机,在这之后再执行分包处理队列
|
|
414
416
|
appScriptRawRequest: '',
|
|
415
417
|
appScriptPromise: null,
|
|
418
|
+
appScriptPromiseResolve: null,
|
|
416
419
|
// 记录entry依赖关系,用于体积分析
|
|
417
420
|
entryNodesMap: {},
|
|
418
421
|
// 记录entryModule与entryNode的对应关系,用于体积分析
|
|
@@ -590,12 +593,10 @@ class MpxWebpackPlugin {
|
|
|
590
593
|
if (module.rawRequest === mpx.appScriptRawRequest) {
|
|
591
594
|
// 避免模块request重名,只对第一次匹配到的模块进行代理
|
|
592
595
|
mpx.appScriptRawRequest = ''
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
})
|
|
596
|
+
proxyedCallback = (err) => {
|
|
597
|
+
mpx.appScriptPromiseResolve()
|
|
598
|
+
return callback(err)
|
|
599
|
+
}
|
|
599
600
|
}
|
|
600
601
|
return rawProcessModuleDependencies.apply(compilation, [module, proxyedCallback])
|
|
601
602
|
}
|
package/lib/loader.js
CHANGED
|
@@ -273,9 +273,8 @@ module.exports = function (content) {
|
|
|
273
273
|
if (!isProduction) {
|
|
274
274
|
globalInjectCode += `global.currentResource = ${JSON.stringify(filePath)}\n`
|
|
275
275
|
}
|
|
276
|
-
if (ctorType === 'app' && i18n && !mpx.forceDisableInject) {
|
|
277
|
-
globalInjectCode += `global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}\n`
|
|
278
276
|
|
|
277
|
+
if (i18n && (ctorType === 'app' || (ctorType === 'page' && queryObj.isIndependent)) && !mpx.forceDisableInject) {
|
|
279
278
|
const i18nMethodsVar = 'i18nMethods'
|
|
280
279
|
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
281
280
|
const i18nWxsLoaderPath = normalize.lib('wxs/wxs-i18n-loader.js')
|
|
@@ -293,7 +292,10 @@ module.exports = function (content) {
|
|
|
293
292
|
})
|
|
294
293
|
this._module.addVariable(i18nMethodsVar, expression, deps)
|
|
295
294
|
|
|
296
|
-
globalInjectCode += `global.
|
|
295
|
+
globalInjectCode += `if (!global.i18n) {
|
|
296
|
+
global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}
|
|
297
|
+
global.i18nMethods = ${i18nMethodsVar}
|
|
298
|
+
}\n`
|
|
297
299
|
}
|
|
298
300
|
// 注入构造函数
|
|
299
301
|
let ctor = 'App'
|
|
@@ -329,7 +331,12 @@ module.exports = function (content) {
|
|
|
329
331
|
}
|
|
330
332
|
if (scriptRequestString) {
|
|
331
333
|
output += 'export * from ' + scriptRequestString + '\n\n'
|
|
332
|
-
if (ctorType === 'app')
|
|
334
|
+
if (ctorType === 'app') {
|
|
335
|
+
mpx.appScriptRawRequest = JSON.parse(scriptRequestString)
|
|
336
|
+
mpx.appScriptPromise = new Promise((resolve) => {
|
|
337
|
+
mpx.appScriptPromiseResolve = resolve
|
|
338
|
+
})
|
|
339
|
+
}
|
|
333
340
|
}
|
|
334
341
|
} else {
|
|
335
342
|
switch (ctorType) {
|
|
@@ -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', {
|
|
@@ -120,6 +120,8 @@ function stringifyArray (value) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
var mpxDashReg = genRegExp('(.+)MpxDash$')
|
|
123
|
+
// 转义字符在wxs正则中存在平台兼容性问题,用[$]规避使用转义字符
|
|
124
|
+
var mpxDashReplaceReg = genRegExp('[$]', 'g')
|
|
123
125
|
|
|
124
126
|
function stringifyObject (value) {
|
|
125
127
|
var res = ''
|
|
@@ -129,7 +131,7 @@ function stringifyObject (value) {
|
|
|
129
131
|
if (value[key]) {
|
|
130
132
|
if (res) res += ' '
|
|
131
133
|
if (mpxDashReg.test(key)) {
|
|
132
|
-
key =
|
|
134
|
+
key = mpxDashReg.exec(key)[1].replace(mpxDashReplaceReg, '-')
|
|
133
135
|
}
|
|
134
136
|
res += key
|
|
135
137
|
}
|
|
@@ -29,6 +29,7 @@ module.exports = function (css, map) {
|
|
|
29
29
|
|
|
30
30
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
31
31
|
|
|
32
|
+
const transRpxFn = mpx.webConfig.transRpxFn
|
|
32
33
|
const testResolveRange = (include = () => true, exclude) => {
|
|
33
34
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
34
35
|
}
|
|
@@ -75,7 +76,7 @@ module.exports = function (css, map) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
if (mpx.mode === 'web') {
|
|
78
|
-
plugins.push(vw)
|
|
79
|
+
plugins.push(vw({ transRpxFn }))
|
|
79
80
|
}
|
|
80
81
|
// source map
|
|
81
82
|
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
|
|
|
@@ -1761,7 +1761,9 @@ function processClass (el, meta) {
|
|
|
1761
1761
|
staticClass = staticClass.replace(/\s+/g, ' ')
|
|
1762
1762
|
if (dynamicClass) {
|
|
1763
1763
|
let staticClassExp = parseMustache(staticClass).result
|
|
1764
|
-
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result
|
|
1764
|
+
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
|
|
1765
|
+
error: error$1
|
|
1766
|
+
})
|
|
1765
1767
|
addAttrs(el, [{
|
|
1766
1768
|
name: targetType,
|
|
1767
1769
|
// swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效
|
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
const babylon = require('@babel/parser')
|
|
2
2
|
const t = require('@babel/types')
|
|
3
3
|
const generate = require('@babel/generator').default
|
|
4
|
-
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
5
4
|
|
|
6
|
-
module.exports = function transDynamicClassExpr (expr) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (t.isObjectExpression(expr)) {
|
|
13
|
-
expr.properties.forEach((property) => {
|
|
14
|
-
if (t.isObjectProperty(property) && !property.computed) {
|
|
15
|
-
const propertyName = property.key.name || property.key.value
|
|
16
|
-
if (/-/.test(propertyName)) {
|
|
17
|
-
property.key = t.identifier(dash2hump(propertyName) + 'MpxDash')
|
|
18
|
-
} else {
|
|
19
|
-
property.key = t.identifier(propertyName)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
5
|
+
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
6
|
+
try {
|
|
7
|
+
const ast = babylon.parseExpression(expr, {
|
|
8
|
+
plugins: [
|
|
9
|
+
'objectRestSpread'
|
|
10
|
+
]
|
|
22
11
|
})
|
|
12
|
+
if (t.isObjectExpression(ast)) {
|
|
13
|
+
ast.properties.forEach((property) => {
|
|
14
|
+
if (t.isObjectProperty(property) && !property.computed) {
|
|
15
|
+
const propertyName = property.key.name || property.key.value
|
|
16
|
+
if (/-/.test(propertyName)) {
|
|
17
|
+
if (/\$/.test(propertyName)) {
|
|
18
|
+
error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
19
|
+
} else {
|
|
20
|
+
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return generate(ast, {
|
|
27
|
+
compact: true
|
|
28
|
+
}).code
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return expr
|
|
23
31
|
}
|
|
24
|
-
return generate(expr, {
|
|
25
|
-
compact: true
|
|
26
|
-
}).code
|
|
27
32
|
}
|
package/lib/web/processScript.js
CHANGED
|
@@ -109,12 +109,6 @@ module.exports = function (script, options, callback) {
|
|
|
109
109
|
import Vue from 'vue'
|
|
110
110
|
import VueRouter from 'vue-router'
|
|
111
111
|
Vue.use(VueRouter)
|
|
112
|
-
import BScroll from '@better-scroll/core'
|
|
113
|
-
import PullDown from '@better-scroll/pull-down'
|
|
114
|
-
import ObserveDOM from '@better-scroll/observe-dom'
|
|
115
|
-
BScroll.use(ObserveDOM)
|
|
116
|
-
BScroll.use(PullDown)
|
|
117
|
-
global.BScroll = BScroll
|
|
118
112
|
global.getApp = function(){}
|
|
119
113
|
global.getCurrentPages = function(){
|
|
120
114
|
if(!global.__mpxRouter) return []
|
|
@@ -40,11 +40,16 @@ module.exports = function (content) {
|
|
|
40
40
|
let results = targetPath.unshiftContainer('body', insertNodes) || []
|
|
41
41
|
targetPath.inserted = true
|
|
42
42
|
results.forEach((item) => {
|
|
43
|
-
item.
|
|
43
|
+
item.shouldStopTraverse = true
|
|
44
44
|
})
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
+
ForStatement (path) {
|
|
49
|
+
if (path.shouldStopTraverse) {
|
|
50
|
+
path.stop()
|
|
51
|
+
}
|
|
52
|
+
},
|
|
48
53
|
// 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
|
|
49
54
|
ExportNamedDeclaration (path) {
|
|
50
55
|
if (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.113",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"@types/babel-traverse": "^6.25.4",
|
|
82
82
|
"@types/babel-types": "^7.0.4"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "05ebd038f9f72d8a12dbae6c6f7685dbfa19f1b8"
|
|
85
85
|
}
|