@mpxjs/webpack-plugin 2.7.48 → 2.7.50-alpha.1
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.
|
@@ -7,7 +7,7 @@ const async = require('async')
|
|
|
7
7
|
const parseRequest = require('../utils/parse-request')
|
|
8
8
|
|
|
9
9
|
class DynamicEntryDependency extends NullDependency {
|
|
10
|
-
constructor (request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', range) {
|
|
10
|
+
constructor (request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', range, extraOptions = {}) {
|
|
11
11
|
super()
|
|
12
12
|
this.request = request
|
|
13
13
|
this.entryType = entryType
|
|
@@ -16,6 +16,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
16
16
|
this.relativePath = relativePath
|
|
17
17
|
this.context = context
|
|
18
18
|
this.range = range
|
|
19
|
+
this.extraOptions = extraOptions
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
get type () {
|
|
@@ -117,10 +118,10 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
117
118
|
|
|
118
119
|
// hash会影响最终的codeGenerateResult是否走缓存,由于该dep中resultPath是动态变更的,需要将其更新到hash中,避免错误使用缓存
|
|
119
120
|
updateHash (hash, context) {
|
|
120
|
-
const { resultPath,
|
|
121
|
+
const { resultPath, extraOptions } = this
|
|
121
122
|
if (resultPath) hash.update(resultPath)
|
|
122
|
-
//
|
|
123
|
-
if (
|
|
123
|
+
// 当处理require.async时,插入随机hash使当前module的codeGeneration cache失效,从而执行dep.apply动态获取当前module所属的chunk路径
|
|
124
|
+
if (extraOptions.isRequireAsync) hash.update('' + (+new Date()) + Math.random())
|
|
124
125
|
super.updateHash(hash, context)
|
|
125
126
|
}
|
|
126
127
|
|
|
@@ -133,6 +134,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
133
134
|
write(this.relativePath)
|
|
134
135
|
write(this.context)
|
|
135
136
|
write(this.range)
|
|
137
|
+
write(this.extraOptions)
|
|
136
138
|
super.serialize(context)
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -145,24 +147,40 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
145
147
|
this.relativePath = read()
|
|
146
148
|
this.context = read()
|
|
147
149
|
this.range = read()
|
|
150
|
+
this.extraOptions = read()
|
|
148
151
|
super.deserialize(context)
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
|
|
153
|
-
apply (dep, source,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
apply (dep, source, {
|
|
157
|
+
module,
|
|
158
|
+
chunkGraph
|
|
159
|
+
}) {
|
|
160
|
+
const { resultPath, range, key, outputPath, publicPath, extraOptions } = dep
|
|
161
|
+
|
|
162
|
+
let replaceContent = ''
|
|
163
|
+
|
|
164
|
+
if (outputPath === 'custom-tab-bar/index') {
|
|
165
|
+
// replace with true for custom-tab-bar
|
|
166
|
+
replaceContent = JSON.stringify(true)
|
|
167
|
+
} else if (resultPath) {
|
|
168
|
+
if (extraOptions.isRequireAsync) {
|
|
169
|
+
const relativePath = toPosix(path.relative(publicPath + path.dirname(chunkGraph.getModuleChunks(module)[0].name), resultPath))
|
|
170
|
+
replaceContent = JSON.stringify(relativePath)
|
|
171
|
+
if (extraOptions.retryRequireAsync) {
|
|
172
|
+
replaceContent += `).catch(function (e) {
|
|
173
|
+
return require.async(${JSON.stringify(relativePath)});
|
|
174
|
+
}`
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
replaceContent = JSON.stringify(resultPath)
|
|
178
|
+
}
|
|
162
179
|
} else {
|
|
163
|
-
|
|
164
|
-
source.replace(range[0], range[1] - 1, JSON.stringify(replaceRange))
|
|
180
|
+
replaceContent = JSON.stringify(`mpx_replace_path_${key}`)
|
|
165
181
|
}
|
|
182
|
+
|
|
183
|
+
if (replaceContent) source.replace(range[0], range[1] - 1, replaceContent)
|
|
166
184
|
}
|
|
167
185
|
}
|
|
168
186
|
|
package/lib/index.js
CHANGED
|
@@ -964,13 +964,6 @@ class MpxWebpackPlugin {
|
|
|
964
964
|
args.push(expr.range)
|
|
965
965
|
|
|
966
966
|
const dep = new DynamicEntryDependency(...args)
|
|
967
|
-
if (args[2] === 'custom-tab-bar/index') {
|
|
968
|
-
// replace with true for custom-tab-bar
|
|
969
|
-
dep.customApply = (dep, source) => {
|
|
970
|
-
const { range } = dep
|
|
971
|
-
source.replace(range[0], range[1] - 1, 'true')
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
967
|
parser.state.current.addPresentationalDependency(dep)
|
|
975
968
|
return true
|
|
976
969
|
})
|
|
@@ -986,21 +979,11 @@ class MpxWebpackPlugin {
|
|
|
986
979
|
request = addQuery(request, {}, false, ['root'])
|
|
987
980
|
// 目前仅wx支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
|
|
988
981
|
if (mpx.mode === 'wx') {
|
|
989
|
-
const dep = new DynamicEntryDependency(request, 'export', '', queryObj.root, '', context, range
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
resultPath = toPosix(path.relative(relativePath, resultPath))
|
|
995
|
-
let replaceContent = JSON.stringify(resultPath)
|
|
996
|
-
if (this.options.retryRequireAsync) {
|
|
997
|
-
replaceContent += `).catch(function (e) {
|
|
998
|
-
return require.async(${JSON.stringify(resultPath)});
|
|
999
|
-
}`
|
|
1000
|
-
}
|
|
1001
|
-
source.replace(range[0], range[1] - 1, replaceContent)
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
982
|
+
const dep = new DynamicEntryDependency(request, 'export', '', queryObj.root, '', context, range, {
|
|
983
|
+
isRequireAsync: true,
|
|
984
|
+
retryRequireAsync: !!this.options.retryRequireAsync
|
|
985
|
+
})
|
|
986
|
+
|
|
1004
987
|
parser.state.current.addPresentationalDependency(dep)
|
|
1005
988
|
// 包含require.async的模块不能被concatenate,避免DynamicEntryDependency中无法获取模块chunk以计算相对路径
|
|
1006
989
|
parser.state.module.buildInfo.moduleConcatenationBailout = 'require async'
|
|
@@ -1989,12 +1989,11 @@ function processAtMode (el) {
|
|
|
1989
1989
|
return
|
|
1990
1990
|
}
|
|
1991
1991
|
|
|
1992
|
-
const conditionMap =
|
|
1993
|
-
|
|
1992
|
+
const conditionMap = new Map()
|
|
1994
1993
|
modeStr.split('|').forEach(item => {
|
|
1995
1994
|
const arr = item.split(':')
|
|
1996
|
-
const key = arr[0] ||
|
|
1997
|
-
conditionMap
|
|
1995
|
+
const key = arr[0] || 'noMode'
|
|
1996
|
+
conditionMap.set(key, arr.slice(1))
|
|
1998
1997
|
})
|
|
1999
1998
|
|
|
2000
1999
|
const modeArr = Object.keys(conditionMap)
|
|
@@ -2002,19 +2001,30 @@ function processAtMode (el) {
|
|
|
2002
2001
|
if (modeArr.every(i => isValidMode(i))) {
|
|
2003
2002
|
const attrValue = getAndRemoveAttr(el, attrName).val
|
|
2004
2003
|
const replacedAttrName = attrArr.join('@')
|
|
2005
|
-
|
|
2006
2004
|
const processedAttr = { name: replacedAttrName, value: attrValue }
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2005
|
+
|
|
2006
|
+
for (let [defineMode, defineEnvArr] of conditionMap.entries()) {
|
|
2007
|
+
if (defineMode === 'noMode' || defineMode === mode) {
|
|
2008
|
+
// 命中 env 规则(没有定义env 或者定义的envArr包含当前env)
|
|
2009
|
+
if (!defineEnvArr.length || defineEnvArr.includes(env)) {
|
|
2010
|
+
if (!replacedAttrName) {
|
|
2011
|
+
// 若defineMode 为 noMode,则不论是element,还是attr,都需要经过规则转换
|
|
2012
|
+
if (defineMode !== 'noMode') {
|
|
2013
|
+
el._atModeStatus = 'match'
|
|
2014
|
+
}
|
|
2015
|
+
} else {
|
|
2016
|
+
// 如果命中了指定的mode,则先存在el上,等跑完转换后再挂回去
|
|
2017
|
+
el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
|
|
2018
|
+
}
|
|
2019
|
+
// 完成匹配,直接退出
|
|
2020
|
+
break
|
|
2021
|
+
}
|
|
2022
|
+
} else if (!replacedAttrName) {
|
|
2023
|
+
// 没有命中当前规则,设置为 'mismatch'
|
|
2024
|
+
el._atModeStatus = 'mismatch'
|
|
2010
2025
|
} else {
|
|
2011
|
-
//
|
|
2012
|
-
el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
|
|
2026
|
+
// 如果没命中指定的mode,则该属性删除
|
|
2013
2027
|
}
|
|
2014
|
-
} else if (!replacedAttrName) {
|
|
2015
|
-
el._atModeStatus = 'mismatch'
|
|
2016
|
-
} else {
|
|
2017
|
-
// 如果没命中指定的mode,则该属性删除
|
|
2018
2028
|
}
|
|
2019
2029
|
}
|
|
2020
2030
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.50-alpha.1",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=14.14.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "58fa63ed6dd39f6d01186697a24571c4ef14e4f0"
|
|
84
84
|
}
|