@mpxjs/webpack-plugin 2.9.41 → 2.9.43
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 +4 -0
- package/lib/json-compiler/index.js +29 -6
- package/lib/platform/style/wx/index.js +9 -9
- package/lib/react/script-helper.js +2 -1
- package/lib/resolver/DynamicRuntimePlugin.js +25 -0
- package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
- package/lib/runtime/oc.wxs +3 -4
- package/lib/runtime/stringify.wxs +5 -5
- package/lib/template-compiler/bind-this.js +2 -6
- package/lib/template-compiler/compiler.js +7 -5
- package/lib/template-compiler/trans-dynamic-class-expr.js +11 -4
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const ExternalsPlugin = require('webpack/lib/ExternalsPlugin')
|
|
|
27
27
|
const AddModePlugin = require('./resolver/AddModePlugin')
|
|
28
28
|
const AddEnvPlugin = require('./resolver/AddEnvPlugin')
|
|
29
29
|
const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
|
|
30
|
+
const DynamicRuntimePlugin = require('./resolver/DynamicRuntimePlugin')
|
|
30
31
|
const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
|
|
31
32
|
// const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
|
|
32
33
|
// const HarmonyImportSideEffectDependency = require('webpack/lib/dependencies/HarmonyImportSideEffectDependency')
|
|
@@ -343,6 +344,9 @@ class MpxWebpackPlugin {
|
|
|
343
344
|
if (this.options.env) {
|
|
344
345
|
compiler.options.resolve.plugins.push(addEnvPlugin)
|
|
345
346
|
}
|
|
347
|
+
if (this.options.dynamicRuntime) {
|
|
348
|
+
compiler.options.resolve.plugins.push(new DynamicRuntimePlugin('before-file', 'file'))
|
|
349
|
+
}
|
|
346
350
|
compiler.options.resolve.plugins.push(packageEntryPlugin)
|
|
347
351
|
compiler.options.resolve.plugins.push(new FixDescriptionInfoPlugin())
|
|
348
352
|
compiler.options.resolve.plugins.push(dynamicPlugin)
|
|
@@ -578,12 +578,12 @@ module.exports = function (content) {
|
|
|
578
578
|
const srcCustomKey = config[srcMode].tabBar.customKey
|
|
579
579
|
const srcPath = resolveTabBarPath(srcCustomKey)
|
|
580
580
|
const outputPath = resolveTabBarPath(outputCustomKey)
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
581
|
+
processComponent(`./${srcPath}`, context, {
|
|
582
|
+
outputPath,
|
|
583
|
+
extraOptions: {
|
|
584
|
+
replaceContent: 'true'
|
|
585
|
+
}
|
|
586
|
+
}, (err, entry) => {
|
|
587
587
|
if (err === RESOLVE_IGNORED_ERR) {
|
|
588
588
|
delete tabBar[srcCustomKey]
|
|
589
589
|
return callback()
|
|
@@ -597,6 +597,26 @@ module.exports = function (content) {
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
+
const processAppBar = (appBar, context, callback) => {
|
|
601
|
+
if (appBar) {
|
|
602
|
+
processComponent('./app-bar/index', context, {
|
|
603
|
+
outputPath: 'app-bar/index',
|
|
604
|
+
extraOptions: {
|
|
605
|
+
replaceContent: 'true'
|
|
606
|
+
}
|
|
607
|
+
}, (err, entry) => {
|
|
608
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
609
|
+
return callback()
|
|
610
|
+
}
|
|
611
|
+
if (err) return callback(err)
|
|
612
|
+
appBar.custom = entry // hack for javascript parser call hook.
|
|
613
|
+
callback()
|
|
614
|
+
})
|
|
615
|
+
} else {
|
|
616
|
+
callback()
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
600
620
|
const processPluginGenericsImplementation = (plugin, context, tarRoot, callback) => {
|
|
601
621
|
if (!plugin.genericsImplementation) return callback()
|
|
602
622
|
const relativePath = useRelativePath ? publicPath + tarRoot : ''
|
|
@@ -673,6 +693,9 @@ module.exports = function (content) {
|
|
|
673
693
|
},
|
|
674
694
|
(callback) => {
|
|
675
695
|
processSubPackages(json.subPackages || json.subpackages, this.context, callback)
|
|
696
|
+
},
|
|
697
|
+
(callback) => {
|
|
698
|
+
processAppBar(json.appBar, this.context, callback)
|
|
676
699
|
}
|
|
677
700
|
], (err) => {
|
|
678
701
|
if (err) return callback(err)
|
|
@@ -59,8 +59,8 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
59
59
|
color: 'color',
|
|
60
60
|
default: 'default' // 不校验
|
|
61
61
|
}
|
|
62
|
-
// number 类型支持的单位
|
|
63
|
-
const numberRegExp = /^\s*(\d+(\.\d+)?)(rpx|px|%)
|
|
62
|
+
// number 类型支持的单位(包含auto)
|
|
63
|
+
const numberRegExp = /^\s*((\d+(\.\d+)?)(rpx|px|%)?)|(auto)\s*$/
|
|
64
64
|
// RN 不支持的颜色格式
|
|
65
65
|
const colorRegExp = /^\s*(lab|lch|oklab|oklch|color-mix|color|hwb|lch|light-dark).*$/
|
|
66
66
|
|
|
@@ -70,8 +70,8 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
70
70
|
case ValueType.color: {
|
|
71
71
|
const isNumber = numberRegExp.test(value)
|
|
72
72
|
const isUnsupporttedColor = colorRegExp.test(value)
|
|
73
|
-
isNumber && warn(`
|
|
74
|
-
isUnsupporttedColor && warn('React Native color does not
|
|
73
|
+
isNumber && warn(`Property [${prop}] receives a valid color as value, not a number.`)
|
|
74
|
+
isUnsupporttedColor && warn('React Native\'s supported color format does not contain [lab,lch,oklab,oklch,color-mix,color,hwb,lch,light-dark].')
|
|
75
75
|
return !isNumber && !isUnsupporttedColor
|
|
76
76
|
}
|
|
77
77
|
case ValueType.number: {
|
|
@@ -392,17 +392,17 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
392
392
|
ios: getAbbreviation,
|
|
393
393
|
android: getAbbreviation
|
|
394
394
|
},
|
|
395
|
+
{ // line-height 换算
|
|
396
|
+
test: 'line-height',
|
|
397
|
+
ios: formatLineHeight,
|
|
398
|
+
android: formatLineHeight
|
|
399
|
+
},
|
|
395
400
|
// 值类型校验放到最后
|
|
396
401
|
{ // color 颜色值校验
|
|
397
402
|
test: /.*color.*/i,
|
|
398
403
|
ios: checkCommonValue(ValueType.color),
|
|
399
404
|
android: checkCommonValue(ValueType.color)
|
|
400
405
|
},
|
|
401
|
-
{ // color 颜色值校验
|
|
402
|
-
test: 'line-height',
|
|
403
|
-
ios: formatLineHeight,
|
|
404
|
-
android: formatLineHeight
|
|
405
|
-
},
|
|
406
406
|
{ // number 值校验
|
|
407
407
|
test: /.*width|height|left|right|top|bottom|radius|margin|padding|spacing|offset|size.*/i,
|
|
408
408
|
ios: checkCommonValue(ValueType.number),
|
|
@@ -93,10 +93,11 @@ function buildGlobalParams ({
|
|
|
93
93
|
if (ctorType === 'app') {
|
|
94
94
|
content += `
|
|
95
95
|
global.getApp = function () {}
|
|
96
|
-
global.getCurrentPages = function () {}
|
|
96
|
+
global.getCurrentPages = function () { return [] }
|
|
97
97
|
global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
|
|
98
98
|
global.__mpxGenericsMap = {}
|
|
99
99
|
global.__mpxOptionsMap = {}
|
|
100
|
+
global.__mpxPagesMap = {}
|
|
100
101
|
global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
|
|
101
102
|
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
102
103
|
global.__getAppComponents = function () {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
2
|
+
|
|
3
|
+
const matcher = {
|
|
4
|
+
include: ['@mpxjs/core/src/dynamic/dynamicRenderMixin.empty.js']
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports = class DynamicRuntimePlugin {
|
|
8
|
+
constructor (source, target) {
|
|
9
|
+
this.source = source
|
|
10
|
+
this.target = target
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
apply (resolver) {
|
|
14
|
+
const target = resolver.ensureHook(this.target)
|
|
15
|
+
resolver.getHook(this.source).tapAsync('DynamicRuntimePlugin', (request, resolveContext, callback) => {
|
|
16
|
+
const resourcePath = request.path
|
|
17
|
+
if (matchCondition(resourcePath, matcher)) {
|
|
18
|
+
request.path = resourcePath.replace(/\.empty/, '')
|
|
19
|
+
resolver.doResolve(target, request, 'resolve dynamicRenderMixin file', resolveContext, callback)
|
|
20
|
+
} else {
|
|
21
|
+
callback()
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/runtime/oc.wxs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// 可选链wxs
|
|
2
2
|
module.exports.g = function (val, valKeyArr) {
|
|
3
3
|
var res = val
|
|
4
|
-
if (typeof val !== 'object') {
|
|
5
|
-
return undefined
|
|
6
|
-
}
|
|
7
4
|
var len = valKeyArr.length
|
|
8
5
|
var i = 0
|
|
9
6
|
while (i < len) {
|
|
10
|
-
if (
|
|
7
|
+
if (typeof res !== 'object' || res === null) {
|
|
8
|
+
res = undefined
|
|
11
9
|
break
|
|
12
10
|
}
|
|
11
|
+
res = res[valKeyArr[i]]
|
|
13
12
|
i++
|
|
14
13
|
}
|
|
15
14
|
return res
|
|
@@ -137,9 +137,9 @@ function stringifyArray (value) {
|
|
|
137
137
|
return res
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
var
|
|
141
|
-
|
|
142
|
-
var
|
|
140
|
+
var mpxEscapeReg = genRegExp('(.+)MpxEscape$')
|
|
141
|
+
var dashEscapeReg = genRegExp('_da_', 'g')
|
|
142
|
+
var spaceEscapeReg = genRegExp('_sp_', 'g')
|
|
143
143
|
|
|
144
144
|
function stringifyObject (value) {
|
|
145
145
|
var res = ''
|
|
@@ -148,8 +148,8 @@ function stringifyObject (value) {
|
|
|
148
148
|
var key = objKeys[i]
|
|
149
149
|
if (value[key]) {
|
|
150
150
|
if (res) res += ' '
|
|
151
|
-
if (
|
|
152
|
-
key =
|
|
151
|
+
if (mpxEscapeReg.test(key)) {
|
|
152
|
+
key = mpxEscapeReg.exec(key)[1].replace(dashEscapeReg, '-').replace(spaceEscapeReg, ' ')
|
|
153
153
|
}
|
|
154
154
|
res += key
|
|
155
155
|
}
|
|
@@ -127,12 +127,8 @@ function checkDelAndGetPath (path) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (t.isMemberExpression(parent) && parent.computed) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
} else {
|
|
133
|
-
canDel = false
|
|
134
|
-
break
|
|
135
|
-
}
|
|
130
|
+
canDel = false
|
|
131
|
+
break
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
if (t.isLogicalExpression(parent)) { // case: a || ((b || c) && d)
|
|
@@ -1654,9 +1654,10 @@ function processFor (el) {
|
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
1656
|
|
|
1657
|
-
function processRefReact (el,
|
|
1657
|
+
function processRefReact (el, meta) {
|
|
1658
1658
|
const val = getAndRemoveAttr(el, config[mode].directive.ref).val
|
|
1659
|
-
|
|
1659
|
+
// rn中只有内建组件能被作为node ref处理
|
|
1660
|
+
const type = el.isBuiltIn ? 'node' : 'component'
|
|
1660
1661
|
if (val) {
|
|
1661
1662
|
if (!meta.refs) {
|
|
1662
1663
|
meta.refs = []
|
|
@@ -1949,7 +1950,7 @@ function processText (el) {
|
|
|
1949
1950
|
// RN中文字需被Text包裹
|
|
1950
1951
|
function processWrapTextReact (el) {
|
|
1951
1952
|
const parentTag = el.parent.tag
|
|
1952
|
-
if (parentTag !== 'mpx-text' && parentTag !== 'Text') {
|
|
1953
|
+
if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
|
|
1953
1954
|
const wrapper = createASTElement('Text')
|
|
1954
1955
|
replaceNode(el, wrapper, true)
|
|
1955
1956
|
addChild(wrapper, el)
|
|
@@ -1970,7 +1971,7 @@ function processWrapTextReact (el) {
|
|
|
1970
1971
|
// }
|
|
1971
1972
|
|
|
1972
1973
|
function injectWxs (meta, module, src) {
|
|
1973
|
-
if (runtimeCompile || addWxsModule(meta, module, src)) {
|
|
1974
|
+
if (runtimeCompile || addWxsModule(meta, module, src) || isReact(mode)) {
|
|
1974
1975
|
return
|
|
1975
1976
|
}
|
|
1976
1977
|
|
|
@@ -2522,7 +2523,7 @@ function processElement (el, root, options, meta) {
|
|
|
2522
2523
|
// 预处理代码维度条件编译
|
|
2523
2524
|
processIf(el)
|
|
2524
2525
|
processFor(el)
|
|
2525
|
-
processRefReact(el,
|
|
2526
|
+
processRefReact(el, meta)
|
|
2526
2527
|
processStyleReact(el)
|
|
2527
2528
|
processEventReact(el, options, meta)
|
|
2528
2529
|
processComponentIs(el, options)
|
|
@@ -2573,6 +2574,7 @@ function closeElement (el, meta, options) {
|
|
|
2573
2574
|
return
|
|
2574
2575
|
}
|
|
2575
2576
|
if (isReact(mode)) {
|
|
2577
|
+
postProcessWxs(el, meta)
|
|
2576
2578
|
postProcessForReact(el)
|
|
2577
2579
|
postProcessIfReact(el)
|
|
2578
2580
|
return
|
|
@@ -2,6 +2,7 @@ const babylon = require('@babel/parser')
|
|
|
2
2
|
const t = require('@babel/types')
|
|
3
3
|
const traverse = require('@babel/traverse').default
|
|
4
4
|
const generate = require('@babel/generator').default
|
|
5
|
+
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
5
6
|
const escapeReg = /[()[\]{}#!.:,%'"+$]/g
|
|
6
7
|
const escapeMap = {
|
|
7
8
|
'(': '_pl_',
|
|
@@ -31,6 +32,12 @@ function mpEscape (str) {
|
|
|
31
32
|
})
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function keyEscape (str) {
|
|
36
|
+
let result = str.replace(/-/g, '_da_').replace(/\s+/g, '_sp_')
|
|
37
|
+
if (result !== str) result += 'MpxEscape'
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
35
42
|
try {
|
|
36
43
|
const ast = babylon.parse(expr, {
|
|
@@ -42,10 +49,10 @@ module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
|
42
49
|
ObjectExpression (path) {
|
|
43
50
|
path.node.properties.forEach((property) => {
|
|
44
51
|
if (t.isObjectProperty(property) && !property.computed) {
|
|
45
|
-
|
|
46
|
-
propertyName = mpEscape(
|
|
47
|
-
if (
|
|
48
|
-
|
|
52
|
+
const rawPropertyName = property.key.name || property.key.value
|
|
53
|
+
const propertyName = keyEscape(mpEscape(rawPropertyName))
|
|
54
|
+
if (!isValidIdentifierStr(propertyName)) {
|
|
55
|
+
error && error(`Dynamic classname [${rawPropertyName}] can not be escaped as a valid identifier, which is not supported.`)
|
|
49
56
|
} else {
|
|
50
57
|
property.key = t.identifier(propertyName)
|
|
51
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.43",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=14.14.0"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "92a347518d15400f87c380bc7248b8b6254631cf"
|
|
89
89
|
}
|