@mpxjs/webpack-plugin 2.7.18 → 2.7.24
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/DynamicEntryDependency.js +2 -2
- package/lib/index.js +22 -6
- package/lib/json-compiler/helper.js +1 -1
- package/lib/json-compiler/index.js +2 -1
- package/lib/platform/template/wx/index.js +28 -1
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +1 -1
- package/lib/runtime/optionProcessor.js +45 -0
- package/lib/template-compiler/compiler.js +19 -11
- package/lib/utils/eval-json-js.js +1 -0
- package/lib/utils/get-entry-name.js +3 -3
- package/lib/utils/get-json-content.js +0 -1
- package/lib/web/processJSON.js +2 -4
- package/lib/web/processScript.js +2 -2
- package/package.json +2 -2
|
@@ -114,8 +114,8 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
114
114
|
updateHash (hash, context) {
|
|
115
115
|
const { resultPath, relativePath } = this
|
|
116
116
|
if (resultPath) hash.update(resultPath)
|
|
117
|
-
// relativePath为MPX_CURRENT_CHUNK
|
|
118
|
-
if (relativePath === MPX_CURRENT_CHUNK) hash.update('' + Math.random())
|
|
117
|
+
// relativePath为MPX_CURRENT_CHUNK时,插入随机hash使当前module的codeGeneration cache失效,从而执行dep.apply动态获取当前module所属的chunk路径
|
|
118
|
+
if (relativePath === MPX_CURRENT_CHUNK) hash.update('' + (+new Date()) + Math.random())
|
|
119
119
|
super.updateHash(hash, context)
|
|
120
120
|
}
|
|
121
121
|
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const ExternalsPlugin = require('webpack/lib/ExternalsPlugin')
|
|
|
22
22
|
const AddModePlugin = require('./resolver/AddModePlugin')
|
|
23
23
|
const AddEnvPlugin = require('./resolver/AddEnvPlugin')
|
|
24
24
|
const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
|
|
25
|
+
const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
|
|
25
26
|
// const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
|
|
26
27
|
// const HarmonyImportSideEffectDependency = require('webpack/lib/dependencies/HarmonyImportSideEffectDependency')
|
|
27
28
|
// const RequireHeaderDependency = require('webpack/lib/dependencies/RequireHeaderDependency')
|
|
@@ -302,6 +303,7 @@ class MpxWebpackPlugin {
|
|
|
302
303
|
compiler.options.resolve.plugins.push(addEnvPlugin)
|
|
303
304
|
}
|
|
304
305
|
compiler.options.resolve.plugins.push(packageEntryPlugin)
|
|
306
|
+
compiler.options.resolve.plugins.push(new FixDescriptionInfoPlugin())
|
|
305
307
|
|
|
306
308
|
let splitChunksPlugin
|
|
307
309
|
let splitChunksOptions
|
|
@@ -789,14 +791,25 @@ class MpxWebpackPlugin {
|
|
|
789
791
|
}
|
|
790
792
|
}
|
|
791
793
|
} else if (independent) {
|
|
792
|
-
// ContextModule/RawModule
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
794
|
+
// ContextModule/RawModule/ExternalModule等只在独立分包的情况下添加分包标记,其余默认不添加
|
|
795
|
+
const hackModuleIdentifier = (module) => {
|
|
796
|
+
const postfix = `|independent=${independent}|${currentPackageRoot}`
|
|
797
|
+
const rawIdentifier = module.identifier
|
|
798
|
+
if (rawIdentifier && !rawIdentifier.__mpxHacked) {
|
|
799
|
+
module.identifier = () => {
|
|
800
|
+
return rawIdentifier.call(module) + postfix
|
|
801
|
+
}
|
|
802
|
+
module.identifier.__mpxHacked = true
|
|
798
803
|
}
|
|
799
804
|
}
|
|
805
|
+
hackModuleIdentifier(module)
|
|
806
|
+
const rawCallback = callback
|
|
807
|
+
callback = (err, module) => {
|
|
808
|
+
// 因为文件缓存的存在,前面hack identifier的行为对于从文件缓存中创建得到的module并不生效,因此需要在回调中进行二次hack处理
|
|
809
|
+
if (err) return rawCallback(err)
|
|
810
|
+
hackModuleIdentifier(module)
|
|
811
|
+
rawCallback(null, module)
|
|
812
|
+
}
|
|
800
813
|
}
|
|
801
814
|
return rawAddModule.call(compilation, module, callback)
|
|
802
815
|
}
|
|
@@ -951,6 +964,9 @@ class MpxWebpackPlugin {
|
|
|
951
964
|
parser.state.current.addDependency(dep)
|
|
952
965
|
}
|
|
953
966
|
return true
|
|
967
|
+
} else {
|
|
968
|
+
compilation.errors.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
|
|
969
|
+
return true
|
|
954
970
|
}
|
|
955
971
|
}
|
|
956
972
|
}
|
|
@@ -12,7 +12,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
12
12
|
const resolveMode = mpx.resolveMode
|
|
13
13
|
const externals = mpx.externals
|
|
14
14
|
const root = mpx.projectRoot
|
|
15
|
-
const publicPath = loaderContext._compilation
|
|
15
|
+
const publicPath = loaderContext._compilation?.outputOptions.publicPath || ''
|
|
16
16
|
const pathHash = mpx.pathHash
|
|
17
17
|
const getOutputPath = mpx.getOutputPath
|
|
18
18
|
const mode = mpx.mode
|
|
@@ -96,6 +96,7 @@ module.exports = function (content) {
|
|
|
96
96
|
} else {
|
|
97
97
|
fs.readFile(file, (err, content) => {
|
|
98
98
|
if (err) return callback(err)
|
|
99
|
+
if (!this._compilation) return callback()
|
|
99
100
|
let targetPath = path.relative(context, file)
|
|
100
101
|
this._compilation.assets[targetPath] = {
|
|
101
102
|
size: function size () {
|
|
@@ -350,7 +351,7 @@ module.exports = function (content) {
|
|
|
350
351
|
}
|
|
351
352
|
|
|
352
353
|
const recordIndependent = (root, request) => {
|
|
353
|
-
this._module.addPresentationalDependency(new RecordIndependentDependency(root, request))
|
|
354
|
+
this._module && this._module.addPresentationalDependency(new RecordIndependentDependency(root, request))
|
|
354
355
|
}
|
|
355
356
|
|
|
356
357
|
const processIndependent = (otherConfig, context, tarRoot, callback) => {
|
|
@@ -181,9 +181,36 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
},
|
|
184
|
+
{
|
|
185
|
+
// style样式绑定
|
|
186
|
+
test: /^(style|wx:style)$/,
|
|
187
|
+
web ({ value }, { el }) {
|
|
188
|
+
if (el.isStyleParsed) {
|
|
189
|
+
return false
|
|
190
|
+
}
|
|
191
|
+
let styleBinding = []
|
|
192
|
+
el.isStyleParsed = true
|
|
193
|
+
el.attrsList.map((item, index) => {
|
|
194
|
+
const parsed = parseMustache(item.value)
|
|
195
|
+
if (item.name === 'style') {
|
|
196
|
+
if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
|
|
197
|
+
styleBinding.push(parseMustache(item.value).result)
|
|
198
|
+
} else {
|
|
199
|
+
styleBinding.push(JSON.stringify(item.value))
|
|
200
|
+
}
|
|
201
|
+
} else if (item.name === 'wx:style') {
|
|
202
|
+
styleBinding.push(parseMustache(item.value).result)
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
return {
|
|
206
|
+
name: ':style',
|
|
207
|
+
value: `[${styleBinding}] | transRpxStyle`
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
184
211
|
{
|
|
185
212
|
// 样式类名绑定
|
|
186
|
-
test: /^wx:
|
|
213
|
+
test: /^wx:class$/,
|
|
187
214
|
web ({ name, value }) {
|
|
188
215
|
const dir = this.test.exec(name)[1]
|
|
189
216
|
const parsed = parseMustache(value)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
module.exports = class FixDescriptionInfoPlugin {
|
|
4
|
+
apply (resolver) {
|
|
5
|
+
resolver.hooks.result.tap('FixDescriptionInfoPlugin', (request) => {
|
|
6
|
+
const { path: resourcePath } = request
|
|
7
|
+
const segments = resourcePath.split(path.sep)
|
|
8
|
+
let rootIndex = -1
|
|
9
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
10
|
+
const segment = segments[i]
|
|
11
|
+
if (segment === 'node_modules') {
|
|
12
|
+
rootIndex = segments[i + 1].startsWith('@') ? i + 2 : i + 1
|
|
13
|
+
break
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (rootIndex !== -1) {
|
|
17
|
+
const descriptionFileRoot = segments.slice(0, rootIndex + 1).join(path.sep)
|
|
18
|
+
const descriptionFilePath = path.join(descriptionFileRoot, 'package.json')
|
|
19
|
+
if (descriptionFilePath !== request.descriptionFilePath) {
|
|
20
|
+
Object.assign(request, {
|
|
21
|
+
descriptionFileRoot,
|
|
22
|
+
descriptionFilePath
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -16,7 +16,7 @@ module.exports = class PackageEntryPlugin {
|
|
|
16
16
|
*/
|
|
17
17
|
apply (resolver) {
|
|
18
18
|
const target = resolver.ensureHook(this.target)
|
|
19
|
-
resolver.getHook(this.source).tapAsync('
|
|
19
|
+
resolver.getHook(this.source).tapAsync('PackageEntryPlugin', (request, resolveContext, callback) => {
|
|
20
20
|
if (request.miniprogram) return callback()
|
|
21
21
|
let { path: resourcePath, descriptionFileData, descriptionFileRoot } = request
|
|
22
22
|
if (request.miniprogram || !descriptionFileData) return callback()
|
|
@@ -85,6 +85,51 @@ export default function processOption (
|
|
|
85
85
|
}
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
+
Vue.filter('transRpxStyle', style => {
|
|
89
|
+
const defaultTransRpxFn = function (match, $1) {
|
|
90
|
+
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
91
|
+
return '' + ($1 * rpx2vwRatio) + 'vw'
|
|
92
|
+
}
|
|
93
|
+
const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
|
|
94
|
+
const parsedStyleObj = {}
|
|
95
|
+
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
96
|
+
const parseStyleText = (cssText) => {
|
|
97
|
+
const listDelimiter = /;(?![^(]*\))/g
|
|
98
|
+
const propertyDelimiter = /:(.+)/
|
|
99
|
+
if (typeof cssText === 'string') {
|
|
100
|
+
cssText.split(listDelimiter).forEach((item) => {
|
|
101
|
+
if (item) {
|
|
102
|
+
var tmp = item.split(propertyDelimiter)
|
|
103
|
+
tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
} else if (typeof cssText === 'object') {
|
|
107
|
+
if (Array.isArray(cssText)) {
|
|
108
|
+
cssText.forEach(cssItem => {
|
|
109
|
+
parseStyleText(cssItem)
|
|
110
|
+
})
|
|
111
|
+
} else {
|
|
112
|
+
Object.assign(parsedStyleObj, cssText)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const transRpxStyleFn = (val) => {
|
|
117
|
+
if (typeof val === 'string' && val.indexOf('rpx') > 0) {
|
|
118
|
+
return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
|
|
119
|
+
}
|
|
120
|
+
return val
|
|
121
|
+
}
|
|
122
|
+
if (style) {
|
|
123
|
+
style.forEach(item => {
|
|
124
|
+
parseStyleText(item)
|
|
125
|
+
for (let key in parsedStyleObj) {
|
|
126
|
+
parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
return parsedStyleObj
|
|
131
|
+
})
|
|
132
|
+
|
|
88
133
|
const routes = []
|
|
89
134
|
|
|
90
135
|
for (const pagePath in pagesMap) {
|
|
@@ -1901,20 +1901,20 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1901
1901
|
}
|
|
1902
1902
|
|
|
1903
1903
|
function processShow (el, options, root) {
|
|
1904
|
+
// 开启 virtualhost 全部走 props 传递处理
|
|
1905
|
+
// 未开启 virtualhost 直接绑定 display:none 到节点上
|
|
1904
1906
|
let show = getAndRemoveAttr(el, config[mode].directive.show).val
|
|
1905
1907
|
if (mode === 'swan') show = wrapMustache(show)
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1908
|
+
|
|
1909
|
+
if (options.hasVirtualHost) {
|
|
1910
|
+
if (options.isComponent && el.parent === root && isRealNode(el)) {
|
|
1911
|
+
if (show !== undefined) {
|
|
1912
|
+
show = `{{${parseMustache(show).result}&&mpxShow}}`
|
|
1913
|
+
} else {
|
|
1914
|
+
show = '{{mpxShow}}'
|
|
1915
|
+
}
|
|
1914
1916
|
}
|
|
1915
|
-
|
|
1916
|
-
if (show !== undefined) {
|
|
1917
|
-
if (isComponentNode(el, options)) {
|
|
1917
|
+
if (isComponentNode(el, options) && show !== undefined) {
|
|
1918
1918
|
if (show === '') {
|
|
1919
1919
|
show = '{{false}}'
|
|
1920
1920
|
}
|
|
@@ -1923,6 +1923,14 @@ function processShow (el, options, root) {
|
|
|
1923
1923
|
value: show
|
|
1924
1924
|
}])
|
|
1925
1925
|
} else {
|
|
1926
|
+
processShowStyle()
|
|
1927
|
+
}
|
|
1928
|
+
} else {
|
|
1929
|
+
processShowStyle()
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function processShowStyle () {
|
|
1933
|
+
if (show !== undefined) {
|
|
1926
1934
|
const showExp = parseMustache(show).result
|
|
1927
1935
|
let oldStyle = getAndRemoveAttr(el, 'style').val
|
|
1928
1936
|
oldStyle = oldStyle ? oldStyle + ';' : ''
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
|
|
3
3
|
module.exports = function evalJSONJS (source, filename, loaderContext) {
|
|
4
|
+
if (!loaderContext._compiler) return {}
|
|
4
5
|
const fs = loaderContext._compiler.inputFileSystem
|
|
5
6
|
const defs = loaderContext.getMpx().defs
|
|
6
7
|
const defKeys = Object.keys(defs)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module.exports = function (loaderContext) {
|
|
2
|
-
|
|
3
|
-
const moduleGraph =
|
|
2
|
+
if (!loaderContext._compilation) return ''
|
|
3
|
+
const moduleGraph = loaderContext._compilation.moduleGraph
|
|
4
4
|
let entryName = ''
|
|
5
|
-
for (const [name, { dependencies }] of
|
|
5
|
+
for (const [name, { dependencies }] of loaderContext._compilation.entries) {
|
|
6
6
|
const entryModule = moduleGraph.getModule(dependencies[0])
|
|
7
7
|
if (entryModule.resource === loaderContext.resource) {
|
|
8
8
|
entryName = name
|
|
@@ -5,7 +5,6 @@ const async = require('async')
|
|
|
5
5
|
const { JSON_JS_EXT } = require('./const')
|
|
6
6
|
|
|
7
7
|
module.exports = function getJSONContent (json, loaderContext, callback) {
|
|
8
|
-
// error process
|
|
9
8
|
if (!loaderContext._compiler) return callback(null, '{}')
|
|
10
9
|
const fs = loaderContext._compiler.inputFileSystem
|
|
11
10
|
async.waterfall([
|
package/lib/web/processJSON.js
CHANGED
|
@@ -219,8 +219,7 @@ module.exports = function (json, {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
pagesMap[resourcePath] = outputPath
|
|
222
|
-
loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
|
|
223
|
-
|
|
222
|
+
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
|
|
224
223
|
localPagesMap[outputPath] = {
|
|
225
224
|
resource: addQuery(resource, { isPage: true }),
|
|
226
225
|
async: tarRoot || queryObj.async,
|
|
@@ -269,8 +268,7 @@ module.exports = function (json, {
|
|
|
269
268
|
}
|
|
270
269
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
271
270
|
componentsMap[resourcePath] = outputPath
|
|
272
|
-
loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
273
|
-
|
|
271
|
+
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
274
272
|
localComponentsMap[name] = {
|
|
275
273
|
resource: addQuery(resource, {
|
|
276
274
|
isComponent: true,
|
package/lib/web/processScript.js
CHANGED
|
@@ -129,8 +129,8 @@ module.exports = function (script, {
|
|
|
129
129
|
global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
|
|
130
130
|
global.__mpxGenericsMap = {}
|
|
131
131
|
global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
|
|
132
|
-
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
133
|
-
|
|
132
|
+
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
|
|
133
|
+
global.__mpxTransRpxFn = ${mpx.webConfig.transRpxFn}\n`
|
|
134
134
|
if (i18n) {
|
|
135
135
|
const i18nObj = Object.assign({}, i18n)
|
|
136
136
|
content += ` import VueI18n from 'vue-i18n'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.24",
|
|
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": "1764785d4da33a7ea9004edc7ea18596262c7969"
|
|
84
84
|
}
|