@mpxjs/webpack-plugin 2.9.29 → 2.9.31
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/dependencies/CommonJsExtractDependency.js +5 -0
- package/lib/dependencies/ImportDependencyTemplate.js +2 -1
- package/lib/index.js +11 -8
- package/lib/loader.js +1 -1
- package/lib/native-loader.js +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
- package/lib/runtime/components/web/mpx-swiper.vue +1 -0
- package/lib/runtime/optionProcessor.js +2 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/style-compiler/index.js +3 -3
- package/lib/template-compiler/compiler.js +1 -1
- package/lib/template-compiler/index.js +1 -1
- package/lib/template-compiler/trans-dynamic-class-expr.js +31 -6
- package/package.json +2 -2
|
@@ -27,7 +27,8 @@ class ImportDependencyTemplate extends (
|
|
|
27
27
|
message: 'import()',
|
|
28
28
|
runtimeRequirements
|
|
29
29
|
})
|
|
30
|
-
|
|
30
|
+
// replace fakeType by 9 to fix require.async to commonjs2 module like 'module.exports = function(){...}'
|
|
31
|
+
content = content.replace(/(__webpack_require__\.t\.bind\(.+,\s*)(\d+)(\s*\))/, (_, p1, p2, p3) => {
|
|
31
32
|
return p1 + '9' + p3
|
|
32
33
|
})
|
|
33
34
|
source.replace(dep.range[0], dep.range[1] - 1, content)
|
package/lib/index.js
CHANGED
|
@@ -302,7 +302,7 @@ class MpxWebpackPlugin {
|
|
|
302
302
|
warnings.push(`webpack options: MpxWebpackPlugin accept options.output.filename to be ${outputFilename} only, custom options.output.filename will be ignored!`)
|
|
303
303
|
}
|
|
304
304
|
compiler.options.output.filename = compiler.options.output.chunkFilename = outputFilename
|
|
305
|
-
if (this.options.optimizeSize) {
|
|
305
|
+
if (this.options.optimizeSize && isProductionLikeMode(compiler.options)) {
|
|
306
306
|
compiler.options.optimization.chunkIds = 'total-size'
|
|
307
307
|
compiler.options.optimization.moduleIds = 'natural'
|
|
308
308
|
compiler.options.optimization.mangleExports = 'size'
|
|
@@ -964,17 +964,20 @@ class MpxWebpackPlugin {
|
|
|
964
964
|
})
|
|
965
965
|
|
|
966
966
|
compilation.hooks.finishModules.tap('MpxWebpackPlugin', (modules) => {
|
|
967
|
-
// 移除extractor
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
connection.
|
|
973
|
-
|
|
967
|
+
// 移除extractor抽取后的空模块,只有生产模式且optimizeSize设置为true时开启
|
|
968
|
+
if (this.options.optimizeSize && isProductionLikeMode(compiler.options)) {
|
|
969
|
+
for (const module of modules) {
|
|
970
|
+
if (module.buildInfo.isEmpty) {
|
|
971
|
+
for (const connection of moduleGraph.getIncomingConnections(module)) {
|
|
972
|
+
if (connection.dependency.type === 'mpx cjs extract') {
|
|
973
|
+
connection.weak = true
|
|
974
|
+
connection.dependency.weak = true
|
|
975
|
+
}
|
|
974
976
|
}
|
|
975
977
|
}
|
|
976
978
|
}
|
|
977
979
|
}
|
|
980
|
+
|
|
978
981
|
// 自动使用分包配置修改splitChunksPlugin配置
|
|
979
982
|
if (splitChunksPlugin) {
|
|
980
983
|
let needInit = false
|
package/lib/loader.js
CHANGED
|
@@ -83,7 +83,7 @@ module.exports = function (content) {
|
|
|
83
83
|
const loaderContext = this
|
|
84
84
|
const isProduction = this.minimize || process.env.NODE_ENV === 'production'
|
|
85
85
|
const filePath = this.resourcePath
|
|
86
|
-
const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID :
|
|
86
|
+
const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : mpx.pathHash(filePath)
|
|
87
87
|
|
|
88
88
|
const parts = parseComponent(content, {
|
|
89
89
|
filePath,
|
package/lib/native-loader.js
CHANGED
|
@@ -188,7 +188,7 @@ module.exports = function (content) {
|
|
|
188
188
|
if (appName) this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID :
|
|
191
|
+
const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : mpx.pathHash(filePath)
|
|
192
192
|
|
|
193
193
|
if (ctorType !== 'app') {
|
|
194
194
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
@@ -308,7 +308,9 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
if (App.onAppInit) {
|
|
311
|
+
global.__mpxAppInit = true
|
|
311
312
|
Object.assign(option, App.onAppInit() || {})
|
|
313
|
+
global.__mpxAppInit = false
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
if (isBrowser && global.__mpxPinia) {
|
|
@@ -137,7 +137,7 @@ function stringifyDynamicClass (value) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
if (typeof value === 'string') {
|
|
140
|
-
return
|
|
140
|
+
return value
|
|
141
141
|
} else {
|
|
142
142
|
return ''
|
|
143
143
|
}
|
|
@@ -245,7 +245,7 @@ module.exports = {
|
|
|
245
245
|
if (typeof staticClass !== 'string') {
|
|
246
246
|
return console.log('Template attr class must be a string!')
|
|
247
247
|
}
|
|
248
|
-
return concat(staticClass, stringifyDynamicClass(dynamicClass))
|
|
248
|
+
return concat(staticClass, mpEscape(stringifyDynamicClass(dynamicClass)))
|
|
249
249
|
},
|
|
250
250
|
stringifyStyle: function (staticStyle, dynamicStyle) {
|
|
251
251
|
var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const postcss = require('postcss')
|
|
3
3
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
4
|
-
const { MPX_ROOT_VIEW
|
|
4
|
+
const { MPX_ROOT_VIEW } = require('../utils/const')
|
|
5
5
|
const rpx = require('./plugins/rpx')
|
|
6
6
|
const vw = require('./plugins/vw')
|
|
7
7
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
@@ -15,7 +15,7 @@ module.exports = function (css, map) {
|
|
|
15
15
|
const cb = this.async()
|
|
16
16
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
17
17
|
const mpx = this.getMpx()
|
|
18
|
-
const id = queryObj.moduleId || queryObj.mid ||
|
|
18
|
+
const id = queryObj.moduleId || queryObj.mid || mpx.pathHash(resourcePath)
|
|
19
19
|
const appInfo = mpx.appInfo
|
|
20
20
|
const defs = mpx.defs
|
|
21
21
|
const mode = mpx.mode
|
|
@@ -90,7 +90,7 @@ module.exports = function (css, map) {
|
|
|
90
90
|
.then(result => {
|
|
91
91
|
// ali环境添加全局样式抹平root差异
|
|
92
92
|
if ((mode === 'ali' || mode === 'web') && isApp) {
|
|
93
|
-
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\
|
|
93
|
+
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\npage { line-height: normal }`
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
for (const warning of result.warnings()) {
|
|
@@ -2182,7 +2182,7 @@ function postProcessComponentIs (el) {
|
|
|
2182
2182
|
}
|
|
2183
2183
|
let range = []
|
|
2184
2184
|
if (el.attrsMap.range) {
|
|
2185
|
-
range = getAndRemoveAttr(el, 'range').val.split(',')
|
|
2185
|
+
range = getAndRemoveAttr(el, 'range').val.split(',').map(item => item.trim())
|
|
2186
2186
|
}
|
|
2187
2187
|
el.components.forEach(function (component) {
|
|
2188
2188
|
if (range.length > 0 && !range.includes(component)) return
|
|
@@ -27,7 +27,7 @@ module.exports = function (raw) {
|
|
|
27
27
|
const hasComment = queryObj.hasComment
|
|
28
28
|
const isNative = queryObj.isNative
|
|
29
29
|
const hasScoped = queryObj.hasScoped
|
|
30
|
-
const moduleId = queryObj.moduleId ||
|
|
30
|
+
const moduleId = queryObj.moduleId || mpx.pathHash(resourcePath)
|
|
31
31
|
|
|
32
32
|
let optimizeRenderLevel = 0
|
|
33
33
|
for (const rule of optimizeRenderRules) {
|
|
@@ -2,6 +2,34 @@ 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 escapeReg = /[()[\]{}#!.:,%'"+$]/g
|
|
6
|
+
const escapeMap = {
|
|
7
|
+
'(': '_pl_',
|
|
8
|
+
')': '_pr_',
|
|
9
|
+
'[': '_bl_',
|
|
10
|
+
']': '_br_',
|
|
11
|
+
'{': '_cl_',
|
|
12
|
+
'}': '_cr_',
|
|
13
|
+
'#': '_h_',
|
|
14
|
+
'!': '_i_',
|
|
15
|
+
'/': '_s_',
|
|
16
|
+
'.': '_d_',
|
|
17
|
+
':': '_c_',
|
|
18
|
+
',': '_2c_',
|
|
19
|
+
'%': '_p_',
|
|
20
|
+
"'": '_q_',
|
|
21
|
+
'"': '_dq_',
|
|
22
|
+
'+': '_a_',
|
|
23
|
+
$: '_si_'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function mpEscape (str) {
|
|
27
|
+
return str.replace(escapeReg, function (match) {
|
|
28
|
+
if (escapeMap[match]) return escapeMap[match]
|
|
29
|
+
// unknown escaped
|
|
30
|
+
return '_u_'
|
|
31
|
+
})
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
7
35
|
try {
|
|
@@ -14,13 +42,10 @@ module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
|
14
42
|
ObjectExpression (path) {
|
|
15
43
|
path.node.properties.forEach((property) => {
|
|
16
44
|
if (t.isObjectProperty(property) && !property.computed) {
|
|
17
|
-
|
|
45
|
+
let propertyName = property.key.name || property.key.value
|
|
46
|
+
propertyName = mpEscape(propertyName)
|
|
18
47
|
if (/-/.test(propertyName)) {
|
|
19
|
-
|
|
20
|
-
error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
21
|
-
} else {
|
|
22
|
-
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
23
|
-
}
|
|
48
|
+
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
24
49
|
} else {
|
|
25
50
|
property.key = t.identifier(propertyName)
|
|
26
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.31",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14.14.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "f0fba8b8505519b4c877d9171cd2496da2c97d2d"
|
|
86
86
|
}
|