@mpxjs/webpack-plugin 2.9.42 → 2.9.48
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/platform/style/wx/index.js +9 -9
- package/lib/react/index.js +1 -1
- package/lib/react/processMainScript.js +8 -4
- package/lib/react/processTemplate.js +1 -0
- package/lib/react/script-helper.js +12 -2
- package/lib/resolver/DynamicRuntimePlugin.js +25 -0
- 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 +3 -2
- package/lib/template-compiler/trans-dynamic-class-expr.js +11 -4
- package/lib/web/index.js +1 -5
- package/lib/web/processMainScript.js +1 -9
- package/lib/web/script-helper.js +12 -11
- 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)
|
|
@@ -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),
|
package/lib/react/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
// 该文件下的字符串语句需要使用 es5 语法
|
|
2
2
|
const addQuery = require('../utils/add-query')
|
|
3
|
-
|
|
4
3
|
const {
|
|
5
|
-
stringifyRequest
|
|
4
|
+
stringifyRequest,
|
|
5
|
+
buildI18n
|
|
6
6
|
} = require('./script-helper')
|
|
7
7
|
|
|
8
|
-
module.exports = function (
|
|
8
|
+
module.exports = function ({
|
|
9
9
|
loaderContext
|
|
10
10
|
}, callback) {
|
|
11
|
-
const { projectName } = loaderContext.getMpx()
|
|
11
|
+
const { i18n, projectName } = loaderContext.getMpx()
|
|
12
12
|
|
|
13
13
|
let output = 'import { AppRegistry } from \'react-native\'\n'
|
|
14
|
+
|
|
15
|
+
if (i18n) {
|
|
16
|
+
output += buildI18n({ loaderContext })
|
|
17
|
+
}
|
|
14
18
|
// 此处可添加前置于App执行的语句
|
|
15
19
|
output += `var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
|
|
16
20
|
output += `AppRegistry.registerComponent(${JSON.stringify(projectName)}, () => App)\n`
|
|
@@ -2,6 +2,7 @@ const loaderUtils = require('loader-utils')
|
|
|
2
2
|
const createHelpers = require('../helpers')
|
|
3
3
|
const parseRequest = require('../utils/parse-request')
|
|
4
4
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
5
|
+
const normalize = require('../utils/normalize')
|
|
5
6
|
|
|
6
7
|
function stringifyRequest (loaderContext, request) {
|
|
7
8
|
return loaderUtils.stringifyRequest(loaderContext, request)
|
|
@@ -93,10 +94,11 @@ function buildGlobalParams ({
|
|
|
93
94
|
if (ctorType === 'app') {
|
|
94
95
|
content += `
|
|
95
96
|
global.getApp = function () {}
|
|
96
|
-
global.getCurrentPages = function () {}
|
|
97
|
+
global.getCurrentPages = function () { return [] }
|
|
97
98
|
global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
|
|
98
99
|
global.__mpxGenericsMap = {}
|
|
99
100
|
global.__mpxOptionsMap = {}
|
|
101
|
+
global.__mpxPagesMap = {}
|
|
100
102
|
global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
|
|
101
103
|
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
102
104
|
global.__getAppComponents = function () {
|
|
@@ -124,10 +126,18 @@ global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n`
|
|
|
124
126
|
return content
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
function buildI18n ({ loaderContext }) {
|
|
130
|
+
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
131
|
+
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
132
|
+
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
133
|
+
return `require(${stringifyRequest(loaderContext, i18nWxsRequest)})\n`
|
|
134
|
+
}
|
|
135
|
+
|
|
127
136
|
module.exports = {
|
|
128
137
|
buildPagesMap,
|
|
129
138
|
buildComponentsMap,
|
|
130
139
|
getRequireScript,
|
|
131
140
|
buildGlobalParams,
|
|
132
|
-
stringifyRequest
|
|
141
|
+
stringifyRequest,
|
|
142
|
+
buildI18n
|
|
133
143
|
}
|
|
@@ -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)
|
|
@@ -1950,7 +1950,7 @@ function processText (el) {
|
|
|
1950
1950
|
// RN中文字需被Text包裹
|
|
1951
1951
|
function processWrapTextReact (el) {
|
|
1952
1952
|
const parentTag = el.parent.tag
|
|
1953
|
-
if (parentTag !== 'mpx-text' && parentTag !== 'Text') {
|
|
1953
|
+
if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
|
|
1954
1954
|
const wrapper = createASTElement('Text')
|
|
1955
1955
|
replaceNode(el, wrapper, true)
|
|
1956
1956
|
addChild(wrapper, el)
|
|
@@ -1971,7 +1971,7 @@ function processWrapTextReact (el) {
|
|
|
1971
1971
|
// }
|
|
1972
1972
|
|
|
1973
1973
|
function injectWxs (meta, module, src) {
|
|
1974
|
-
if (runtimeCompile || addWxsModule(meta, module, src)) {
|
|
1974
|
+
if (runtimeCompile || addWxsModule(meta, module, src) || isReact(mode)) {
|
|
1975
1975
|
return
|
|
1976
1976
|
}
|
|
1977
1977
|
|
|
@@ -2574,6 +2574,7 @@ function closeElement (el, meta, options) {
|
|
|
2574
2574
|
return
|
|
2575
2575
|
}
|
|
2576
2576
|
if (isReact(mode)) {
|
|
2577
|
+
postProcessWxs(el, meta)
|
|
2577
2578
|
postProcessForReact(el)
|
|
2578
2579
|
postProcessIfReact(el)
|
|
2579
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/lib/web/index.js
CHANGED
|
@@ -35,13 +35,9 @@ module.exports = function ({
|
|
|
35
35
|
}, callback)
|
|
36
36
|
},
|
|
37
37
|
(jsonRes, callback) => {
|
|
38
|
-
processMainScript(
|
|
38
|
+
processMainScript({
|
|
39
39
|
loaderContext,
|
|
40
|
-
srcMode,
|
|
41
|
-
moduleId,
|
|
42
|
-
isProduction,
|
|
43
40
|
jsonConfig: jsonRes.jsonObj,
|
|
44
|
-
outputPath: queryObj.outputPath || '',
|
|
45
41
|
localComponentsMap: jsonRes.localComponentsMap,
|
|
46
42
|
tabBar: jsonRes.jsonObj.tabBar,
|
|
47
43
|
tabBarMap: jsonRes.tabBarMap,
|
|
@@ -12,11 +12,8 @@ const {
|
|
|
12
12
|
buildI18n
|
|
13
13
|
} = require('./script-helper')
|
|
14
14
|
|
|
15
|
-
module.exports = function (
|
|
15
|
+
module.exports = function ({
|
|
16
16
|
loaderContext,
|
|
17
|
-
srcMode,
|
|
18
|
-
moduleId,
|
|
19
|
-
isProduction,
|
|
20
17
|
jsonConfig,
|
|
21
18
|
localComponentsMap,
|
|
22
19
|
tabBar,
|
|
@@ -40,8 +37,6 @@ module.exports = function (script, {
|
|
|
40
37
|
jsonConfig
|
|
41
38
|
})
|
|
42
39
|
|
|
43
|
-
const scriptSrcMode = script ? script.mode || srcMode : srcMode
|
|
44
|
-
|
|
45
40
|
let output = 'import \'@mpxjs/webpack-plugin/lib/runtime/base.styl\'\n'
|
|
46
41
|
// hasUnoCSS由@mpxjs/unocss-plugin注入
|
|
47
42
|
if (hasUnoCSS) {
|
|
@@ -58,10 +53,7 @@ Vue.use(VueRouter)\n`
|
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
output += buildGlobalParams({
|
|
61
|
-
moduleId,
|
|
62
|
-
scriptSrcMode,
|
|
63
56
|
loaderContext,
|
|
64
|
-
isProduction,
|
|
65
57
|
jsonConfig,
|
|
66
58
|
webConfig,
|
|
67
59
|
isMain: true,
|
package/lib/web/script-helper.js
CHANGED
|
@@ -170,17 +170,18 @@ function buildGlobalParams ({
|
|
|
170
170
|
if (globalTabBar) {
|
|
171
171
|
content += globalTabBar
|
|
172
172
|
}
|
|
173
|
-
} else
|
|
174
|
-
|
|
175
|
-
global.__mpxGenericsMap = global.__mpxGenericsMap || {}
|
|
176
|
-
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
177
|
-
global.__mpxTransRpxFn = ${webConfig.transRpxFn}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
173
|
+
} else {
|
|
174
|
+
if (!hasApp) {
|
|
175
|
+
content += ' global.__mpxGenericsMap = global.__mpxGenericsMap || {}\n'
|
|
176
|
+
content += ' global.__mpxOptionsMap = global.__mpxOptionsMap || {}\n'
|
|
177
|
+
content += ` global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
|
|
178
|
+
}
|
|
179
|
+
content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
|
|
180
|
+
content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
|
|
181
|
+
content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
|
|
182
|
+
if (!isProduction) {
|
|
183
|
+
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
184
|
+
}
|
|
184
185
|
}
|
|
185
186
|
return content
|
|
186
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.48",
|
|
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": "f1bd7c32ec48c4401ab1bf68247bc68834ca932b"
|
|
89
89
|
}
|