@mpxjs/webpack-plugin 2.7.1 → 2.7.5
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/extractor.js +5 -3
- package/lib/index.js +23 -5
- package/lib/loader.js +1 -1
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/style-compiler/plugins/scope-id.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +1 -1
- package/lib/template-compiler/trans-dynamic-class-expr.js +17 -14
- package/lib/wxml/loader.js +1 -1
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxss/loader.js +3 -3
- package/package.json +3 -3
package/lib/extractor.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
16
16
|
const type = queryObj.type
|
|
17
17
|
const index = queryObj.index || 0
|
|
18
18
|
const isStatic = queryObj.isStatic
|
|
19
|
-
const
|
|
19
|
+
const issuerResource = queryObj.issuerResource
|
|
20
20
|
const fromImport = queryObj.fromImport
|
|
21
21
|
const needBabel = queryObj.needBabel
|
|
22
22
|
|
|
@@ -82,7 +82,8 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
82
82
|
// styles为static就两种情况,一种是.mpx中使用src引用样式,第二种为css-loader中处理@import
|
|
83
83
|
// 为了支持持久化缓存,.mpx中使用src引用样式对issueFile asset产生的副作用迁移到ExtractDependency中处理
|
|
84
84
|
case 'styles':
|
|
85
|
-
if (
|
|
85
|
+
if (issuerResource) {
|
|
86
|
+
const issuerFile = mpx.getExtractedFile(issuerResource)
|
|
86
87
|
let relativePath = toPosix(path.relative(path.dirname(issuerFile), file))
|
|
87
88
|
relativePath = fixRelative(relativePath, mode)
|
|
88
89
|
if (fromImport) {
|
|
@@ -92,7 +93,8 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
92
93
|
skipEmit: true,
|
|
93
94
|
extractedInfo: {
|
|
94
95
|
content: `@import "${relativePath}";\n`,
|
|
95
|
-
index
|
|
96
|
+
index,
|
|
97
|
+
pre: true
|
|
96
98
|
}
|
|
97
99
|
})
|
|
98
100
|
}
|
package/lib/index.js
CHANGED
|
@@ -838,6 +838,23 @@ class MpxWebpackPlugin {
|
|
|
838
838
|
mpx.assetsModulesMap.set(filename, modules)
|
|
839
839
|
})
|
|
840
840
|
|
|
841
|
+
const fillExtractedAssetsMap = (assetsMap, { index, content }, filename) => {
|
|
842
|
+
if (assetsMap.has(index)) {
|
|
843
|
+
if (assetsMap.get(index) !== content) {
|
|
844
|
+
compilation.errors.push(new Error(`The extracted file [${filename}] is filled with same index [${index}] and different content:
|
|
845
|
+
old content: ${assetsMap.get(index)}
|
|
846
|
+
new content: ${content}
|
|
847
|
+
please check!`))
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
assetsMap.set(index, content)
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const sortExtractedAssetsMap = (assetsMap) => {
|
|
855
|
+
return [...assetsMap.entries()].sort((a, b) => a[0] - b[0]).map(item => item[1])
|
|
856
|
+
}
|
|
857
|
+
|
|
841
858
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
|
842
859
|
const extractedAssetsMap = new Map()
|
|
843
860
|
for (const module of compilation.modules) {
|
|
@@ -846,19 +863,19 @@ class MpxWebpackPlugin {
|
|
|
846
863
|
if (extractedInfo) {
|
|
847
864
|
let extractedAssets = extractedAssetsMap.get(filename)
|
|
848
865
|
if (!extractedAssets) {
|
|
849
|
-
extractedAssets = []
|
|
866
|
+
extractedAssets = [new Map(), new Map()]
|
|
850
867
|
extractedAssetsMap.set(filename, extractedAssets)
|
|
851
868
|
}
|
|
852
|
-
|
|
869
|
+
fillExtractedAssetsMap(extractedInfo.pre ? extractedAssets[0] : extractedAssets[1], extractedInfo, filename)
|
|
853
870
|
compilation.hooks.moduleAsset.call(module, filename)
|
|
854
871
|
}
|
|
855
872
|
}
|
|
856
873
|
}
|
|
857
874
|
|
|
858
|
-
for (const [filename,
|
|
859
|
-
const sortedExtractedAssets =
|
|
875
|
+
for (const [filename, [pre, normal]] of extractedAssetsMap) {
|
|
876
|
+
const sortedExtractedAssets = [...sortExtractedAssetsMap(pre), ...sortExtractedAssetsMap(normal)]
|
|
860
877
|
const source = new ConcatSource()
|
|
861
|
-
sortedExtractedAssets.forEach((
|
|
878
|
+
sortedExtractedAssets.forEach((content) => {
|
|
862
879
|
if (content) {
|
|
863
880
|
// 处理replace path
|
|
864
881
|
if (/"mpx_replace_path_.*?"/.test(content)) {
|
|
@@ -1344,6 +1361,7 @@ try {
|
|
|
1344
1361
|
const fs = compiler.intermediateFileSystem
|
|
1345
1362
|
const cacheLocation = compiler.options.cache.cacheLocation
|
|
1346
1363
|
return new Promise((resolve) => {
|
|
1364
|
+
if (!cacheLocation) return resolve()
|
|
1347
1365
|
if (typeof fs.rm === 'function') {
|
|
1348
1366
|
fs.rm(cacheLocation, {
|
|
1349
1367
|
recursive: true,
|
package/lib/loader.js
CHANGED
|
@@ -290,7 +290,7 @@ module.exports = function (content) {
|
|
|
290
290
|
...style.src ? {
|
|
291
291
|
...queryObj,
|
|
292
292
|
isStatic: true,
|
|
293
|
-
|
|
293
|
+
issuerResource: addQuery(this.resource, { type: 'styles' }, true)
|
|
294
294
|
} : null,
|
|
295
295
|
moduleId,
|
|
296
296
|
scoped
|
|
@@ -85,6 +85,10 @@
|
|
|
85
85
|
animation: {
|
|
86
86
|
type: Boolean,
|
|
87
87
|
default: true
|
|
88
|
+
},
|
|
89
|
+
speed: {
|
|
90
|
+
type: Number,
|
|
91
|
+
default: 1000
|
|
88
92
|
}
|
|
89
93
|
},
|
|
90
94
|
watch: {
|
|
@@ -96,7 +100,7 @@
|
|
|
96
100
|
if (newVal < this.bs.maxScrollX) {
|
|
97
101
|
newVal = this.bs.maxScrollX
|
|
98
102
|
}
|
|
99
|
-
this.bs.scrollTo(newVal, this.bs.y)
|
|
103
|
+
this.bs.scrollTo(newVal, this.bs.y, this.speed)
|
|
100
104
|
},
|
|
101
105
|
y (newVal) {
|
|
102
106
|
this.source = ''
|
|
@@ -106,7 +110,7 @@
|
|
|
106
110
|
if (newVal < this.bs.maxScrollY) {
|
|
107
111
|
newVal = this.bs.maxScrollY
|
|
108
112
|
}
|
|
109
|
-
this.bs.scrollTo(this.bs.x, newVal)
|
|
113
|
+
this.bs.scrollTo(this.bs.x, newVal, this.speed)
|
|
110
114
|
},
|
|
111
115
|
scaleValue (newVal) {
|
|
112
116
|
this.isZooming = true
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
const babylon = require('@babel/parser')
|
|
2
2
|
const t = require('@babel/types')
|
|
3
|
+
const traverse = require('@babel/traverse').default
|
|
3
4
|
const generate = require('@babel/generator').default
|
|
4
5
|
|
|
5
6
|
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
6
7
|
try {
|
|
7
|
-
const ast = babylon.
|
|
8
|
+
const ast = babylon.parse(expr, {
|
|
8
9
|
plugins: [
|
|
9
10
|
'objectRestSpread'
|
|
10
11
|
]
|
|
11
12
|
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
traverse(ast, {
|
|
14
|
+
ObjectExpression (path) {
|
|
15
|
+
path.node.properties.forEach((property) => {
|
|
16
|
+
if (t.isObjectProperty(property) && !property.computed) {
|
|
17
|
+
const propertyName = property.key.name || property.key.value
|
|
18
|
+
if (/-/.test(propertyName)) {
|
|
19
|
+
if (/\$/.test(propertyName)) {
|
|
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
|
+
}
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return generate(ast, {
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
return generate(ast.program.body[0].expression, {
|
|
27
30
|
compact: true
|
|
28
31
|
}).code
|
|
29
32
|
} catch (e) {
|
package/lib/wxml/loader.js
CHANGED
|
@@ -99,7 +99,7 @@ module.exports = function (content) {
|
|
|
99
99
|
case config[mode].wxs.tag:
|
|
100
100
|
// 显式传递issuerResource避免模块缓存以及提供给wxs-loader计算相对路径
|
|
101
101
|
extraOptions = {
|
|
102
|
-
|
|
102
|
+
issuerResource: this.resource,
|
|
103
103
|
isStatic: true
|
|
104
104
|
}
|
|
105
105
|
requestString = getRequestString('wxs', { src, mode: localSrcMode }, extraOptions)
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const {
|
|
2
2
|
compareModulesByPreOrderIndexOrIdentifier
|
|
3
3
|
} = require('webpack/lib/util/comparators')
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
assignAscendingModuleIds,
|
|
6
|
+
getUsedModuleIdsAndModules
|
|
7
|
+
} = require('webpack/lib/ids/IdHelpers')
|
|
5
8
|
|
|
6
9
|
/** @typedef {import("../Compiler")} Compiler */
|
|
7
10
|
/** @typedef {import("../Module")} Module */
|
|
@@ -12,19 +15,13 @@ class WxsModuleIdsPlugin {
|
|
|
12
15
|
name: 'WxsModuleIdsPlugin',
|
|
13
16
|
// 放在最前面执行,确保生成的代码模块为数组形式,符合wxs规范
|
|
14
17
|
stage: -1000
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
chunkGraph.getModuleId(m) === null
|
|
23
|
-
)
|
|
24
|
-
.sort(
|
|
25
|
-
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
|
26
|
-
)
|
|
27
|
-
assignAscendingModuleIds(modulesInNaturalOrder, compilation)
|
|
18
|
+
}, () => {
|
|
19
|
+
const [usedIds, modulesInNaturalOrder] =
|
|
20
|
+
getUsedModuleIdsAndModules(compilation)
|
|
21
|
+
modulesInNaturalOrder.sort(
|
|
22
|
+
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
|
23
|
+
)
|
|
24
|
+
assignAscendingModuleIds(usedIds, modulesInNaturalOrder, compilation)
|
|
28
25
|
})
|
|
29
26
|
}
|
|
30
27
|
}
|
package/lib/wxss/loader.js
CHANGED
|
@@ -65,7 +65,7 @@ module.exports = function (content, map) {
|
|
|
65
65
|
alreadyImported[imp.url] = true
|
|
66
66
|
}
|
|
67
67
|
return true
|
|
68
|
-
}).map((imp) => {
|
|
68
|
+
}).map((imp, i) => {
|
|
69
69
|
if (!isUrlRequest(imp.url, root, externals)) {
|
|
70
70
|
return 'exports.push([module.id, ' +
|
|
71
71
|
JSON.stringify('@import url(' + imp.url + ');') + ', ' +
|
|
@@ -73,9 +73,9 @@ module.exports = function (content, map) {
|
|
|
73
73
|
} else {
|
|
74
74
|
const requestString = getRequestString('styles', { src: imp.url }, {
|
|
75
75
|
isStatic: true,
|
|
76
|
-
|
|
76
|
+
issuerResource: this.resource,
|
|
77
77
|
fromImport: true
|
|
78
|
-
})
|
|
78
|
+
}, i)
|
|
79
79
|
return 'exports.push([module.id, ' +
|
|
80
80
|
JSON.stringify('@import "') +
|
|
81
81
|
'+ require(' + requestString + ') +' +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.5",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"consolidate": "^0.15.1",
|
|
33
33
|
"css": "^2.2.1",
|
|
34
34
|
"css-selector-tokenizer": "^0.7.0",
|
|
35
|
-
"cssnano": "^
|
|
35
|
+
"cssnano": "^5.0.16",
|
|
36
36
|
"de-indent": "^1.0.2",
|
|
37
37
|
"fastparse": "^1.1.1",
|
|
38
38
|
"hash-sum": "^1.0.2",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=14.14.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "84d834c2ace18403bb1d4beb8585a1bfaca8e509"
|
|
84
84
|
}
|