@mpxjs/webpack-plugin 2.7.1-beta.3 → 2.7.1-beta.8
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/dependencies/RecordResourceMapDependency.js +13 -4
- package/lib/helpers.js +4 -3
- package/lib/independent-loader.js +2 -0
- package/lib/index.js +63 -29
- package/lib/loader.js +22 -8
- package/lib/native-loader.js +3 -2
- package/package.json +2 -2
|
@@ -29,7 +29,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
29
29
|
const publicPath = compilation.outputOptions.publicPath || ''
|
|
30
30
|
let { resource, entryType, outputPath, relativePath, originEntryNode } = this
|
|
31
31
|
|
|
32
|
-
const { packageRoot, outputPath: filename,
|
|
32
|
+
const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
|
|
33
33
|
resource,
|
|
34
34
|
outputPath,
|
|
35
35
|
resourceType: entryType,
|
|
@@ -49,7 +49,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
49
49
|
// export类型的resultPath需要添加.js后缀
|
|
50
50
|
if (entryType === 'export') resultPath += '.js'
|
|
51
51
|
|
|
52
|
-
if (
|
|
52
|
+
if (alreadyOutputted) return callback(null, { resultPath })
|
|
53
53
|
|
|
54
54
|
if (packageRoot) {
|
|
55
55
|
resource = addQuery(resource, { packageRoot })
|
|
@@ -16,10 +16,19 @@ class RecordResourceMapDependency extends NullDependency {
|
|
|
16
16
|
|
|
17
17
|
mpxAction (module, compilation, callback) {
|
|
18
18
|
const mpx = compilation.__mpx__
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const { resourcePath, resourceType, outputPath, packageRoot } = this
|
|
20
|
+
mpx.recordResourceMap({
|
|
21
|
+
resourcePath,
|
|
22
|
+
resourceType,
|
|
23
|
+
outputPath,
|
|
24
|
+
packageRoot,
|
|
25
|
+
warn (e) {
|
|
26
|
+
compilation.warnings.push(e)
|
|
27
|
+
},
|
|
28
|
+
error (e) {
|
|
29
|
+
compilation.errors.push(e)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
23
32
|
return callback()
|
|
24
33
|
}
|
|
25
34
|
|
package/lib/helpers.js
CHANGED
|
@@ -14,6 +14,7 @@ const defaultLang = {
|
|
|
14
14
|
|
|
15
15
|
module.exports = function createHelpers (loaderContext) {
|
|
16
16
|
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
17
18
|
|
|
18
19
|
function getRequire (type, part, extraOptions, index) {
|
|
19
20
|
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
@@ -35,9 +36,9 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
35
36
|
|
|
36
37
|
function getFakeRequest (type, part) {
|
|
37
38
|
const lang = part.lang || defaultLang[type] || type
|
|
38
|
-
const {
|
|
39
|
-
if (lang === 'json')
|
|
40
|
-
return addQuery(`${resourcePath}.${lang}`,
|
|
39
|
+
const options = { ...queryObj }
|
|
40
|
+
if (lang === 'json') options.asScript = true
|
|
41
|
+
return addQuery(`${resourcePath}.${lang}`, options)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function getRequestString (type, part, extraOptions = {}, index = 0) {
|
|
@@ -41,6 +41,8 @@ module.exports = function (content) {
|
|
|
41
41
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
42
42
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
43
43
|
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
44
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
45
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
44
46
|
}
|
|
45
47
|
output += content
|
|
46
48
|
output += '\n'
|
package/lib/index.js
CHANGED
|
@@ -219,6 +219,24 @@ class MpxWebpackPlugin {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
static getPageEntry (request) {
|
|
223
|
+
return addQuery(request, { isPage: true })
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static getComponentEntry (request) {
|
|
227
|
+
return addQuery(request, { isComponent: true })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static getPluginEntry (request) {
|
|
231
|
+
return addQuery(request, {
|
|
232
|
+
mpx: true,
|
|
233
|
+
extract: true,
|
|
234
|
+
isPlugin: true,
|
|
235
|
+
asScript: true,
|
|
236
|
+
type: 'json'
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
222
240
|
runModeRules (data) {
|
|
223
241
|
const { resourcePath, queryObj } = parseRequest(data.resource)
|
|
224
242
|
if (queryObj.mode) {
|
|
@@ -488,7 +506,9 @@ class MpxWebpackPlugin {
|
|
|
488
506
|
// 记录entryModule与entryNode的对应关系,用于体积分析
|
|
489
507
|
entryNodeModulesMap: new Map(),
|
|
490
508
|
// 记录与asset相关联的modules,用于体积分析
|
|
491
|
-
|
|
509
|
+
assetsModulesMap: new Map(),
|
|
510
|
+
// 记录与asset相关联的ast,用于体积分析和esCheck,避免重复parse
|
|
511
|
+
assetsASTsMap: new Map(),
|
|
492
512
|
usingComponents: {},
|
|
493
513
|
// todo es6 map读写性能高于object,之后会逐步替换
|
|
494
514
|
vueContentCache: new Map(),
|
|
@@ -577,15 +597,42 @@ class MpxWebpackPlugin {
|
|
|
577
597
|
mpx.extractedFilesCache.set(resource, file)
|
|
578
598
|
return file
|
|
579
599
|
},
|
|
600
|
+
recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', warn, error }) => {
|
|
601
|
+
const packageName = packageRoot || 'main'
|
|
602
|
+
const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
|
|
603
|
+
const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
|
|
604
|
+
if (outputPath) {
|
|
605
|
+
if (!currentResourceMap[resourcePath] || currentResourceMap[resourcePath] === true) {
|
|
606
|
+
// 输出路径冲突检测,如果存在输出路径冲突,对输出路径进行重命名
|
|
607
|
+
// todo 用outputPathMap来检测输出路径冲突
|
|
608
|
+
for (let key in currentResourceMap) {
|
|
609
|
+
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
610
|
+
outputPath = mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })
|
|
611
|
+
warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with conflicted outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
|
|
612
|
+
break
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
currentResourceMap[resourcePath] = outputPath
|
|
616
|
+
} else {
|
|
617
|
+
if (currentResourceMap[resourcePath] === outputPath) {
|
|
618
|
+
return true
|
|
619
|
+
} else {
|
|
620
|
+
error && error(new Error(`Current ${resourceType} [${resourcePath}] is already registered with outputPath [${currentResourceMap[resourcePath]}], you can not register it with another outputPath [${outputPath}]!`))
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
} else if (!currentResourceMap[resourcePath]) {
|
|
624
|
+
currentResourceMap[resourcePath] = true
|
|
625
|
+
}
|
|
626
|
+
return false
|
|
627
|
+
},
|
|
580
628
|
// 组件和静态资源的输出规则如下:
|
|
581
629
|
// 1. 主包引用的资源输出至主包
|
|
582
630
|
// 2. 分包引用且主包引用过的资源输出至主包,不在当前分包重复输出
|
|
583
631
|
// 3. 分包引用且无其他包引用的资源输出至当前分包
|
|
584
632
|
// 4. 分包引用且其他分包也引用过的资源,重复输出至当前分包
|
|
585
|
-
getPackageInfo: ({ resource,
|
|
633
|
+
getPackageInfo: ({ resource, resourceType, outputPath, issuerResource, warn, error }) => {
|
|
586
634
|
let packageRoot = ''
|
|
587
635
|
let packageName = 'main'
|
|
588
|
-
let currentResourceMap = {}
|
|
589
636
|
|
|
590
637
|
const { resourcePath } = parseRequest(resource)
|
|
591
638
|
const currentPackageRoot = mpx.currentPackageRoot
|
|
@@ -594,7 +641,6 @@ class MpxWebpackPlugin {
|
|
|
594
641
|
const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
|
|
595
642
|
|
|
596
643
|
if (!resourceMap.main) {
|
|
597
|
-
currentResourceMap = resourceMap
|
|
598
644
|
packageRoot = currentPackageRoot
|
|
599
645
|
packageName = currentPackageName
|
|
600
646
|
} else {
|
|
@@ -625,36 +671,24 @@ class MpxWebpackPlugin {
|
|
|
625
671
|
}
|
|
626
672
|
}
|
|
627
673
|
resourceMap[packageName] = resourceMap[packageName] || {}
|
|
628
|
-
currentResourceMap = resourceMap[packageName]
|
|
629
674
|
}
|
|
630
675
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
642
|
-
outputPath = toPosix(path.join(packageRoot, mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })))
|
|
643
|
-
warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with a conflict outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
|
|
644
|
-
break
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
currentResourceMap[resourcePath] = outputPath
|
|
648
|
-
}
|
|
649
|
-
} else if (!currentResourceMap[resourcePath]) {
|
|
650
|
-
currentResourceMap[resourcePath] = true
|
|
651
|
-
}
|
|
676
|
+
if (outputPath) outputPath = toPosix(path.join(packageRoot, outputPath))
|
|
677
|
+
|
|
678
|
+
const alreadyOutputted = mpx.recordResourceMap({
|
|
679
|
+
resourcePath,
|
|
680
|
+
resourceType,
|
|
681
|
+
outputPath,
|
|
682
|
+
packageRoot,
|
|
683
|
+
warn,
|
|
684
|
+
error
|
|
685
|
+
})
|
|
652
686
|
|
|
653
687
|
return {
|
|
654
688
|
packageName,
|
|
655
689
|
packageRoot,
|
|
656
690
|
outputPath,
|
|
657
|
-
|
|
691
|
+
alreadyOutputted
|
|
658
692
|
}
|
|
659
693
|
}
|
|
660
694
|
}
|
|
@@ -793,9 +827,9 @@ class MpxWebpackPlugin {
|
|
|
793
827
|
})
|
|
794
828
|
|
|
795
829
|
compilation.hooks.moduleAsset.tap('MpxWebpackPlugin', (module, filename) => {
|
|
796
|
-
const modules = mpx.
|
|
830
|
+
const modules = mpx.assetsModulesMap.get(filename) || new Set()
|
|
797
831
|
modules.add(module)
|
|
798
|
-
mpx.
|
|
832
|
+
mpx.assetsModulesMap.set(filename, modules)
|
|
799
833
|
})
|
|
800
834
|
|
|
801
835
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
package/lib/loader.js
CHANGED
|
@@ -225,6 +225,8 @@ module.exports = function (content) {
|
|
|
225
225
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
226
226
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
227
227
|
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
228
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
229
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
228
230
|
}
|
|
229
231
|
|
|
230
232
|
// 为独立分包注入init module
|
|
@@ -232,6 +234,8 @@ module.exports = function (content) {
|
|
|
232
234
|
const independentLoader = normalize.lib('independent-loader.js')
|
|
233
235
|
const independentInitRequest = `!!${independentLoader}!${independent}`
|
|
234
236
|
this._module.addDependency(new CommonJsVariableDependency(independentInitRequest))
|
|
237
|
+
// 避免该模块被concatenate导致注入的independent init没有最先执行
|
|
238
|
+
this._module.buildInfo.moduleConcatenationBailout = 'independent init'
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
// 注入构造函数
|
|
@@ -258,6 +262,10 @@ module.exports = function (content) {
|
|
|
258
262
|
|
|
259
263
|
if (template) {
|
|
260
264
|
const extraOptions = {
|
|
265
|
+
...template.src ? {
|
|
266
|
+
...queryObj,
|
|
267
|
+
resourcePath
|
|
268
|
+
} : null,
|
|
261
269
|
hasScoped,
|
|
262
270
|
hasComment,
|
|
263
271
|
isNative,
|
|
@@ -278,16 +286,16 @@ module.exports = function (content) {
|
|
|
278
286
|
parts.styles.forEach((style, i) => {
|
|
279
287
|
const scoped = style.scoped || autoScope
|
|
280
288
|
const extraOptions = {
|
|
289
|
+
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
290
|
+
...style.src ? {
|
|
291
|
+
...queryObj,
|
|
292
|
+
isStatic: true,
|
|
293
|
+
issuerFile: mpx.getExtractedFile(addQuery(this.resource, { type: 'styles' }, true))
|
|
294
|
+
} : null,
|
|
281
295
|
moduleId,
|
|
282
296
|
scoped
|
|
283
297
|
}
|
|
284
298
|
// require style
|
|
285
|
-
if (style.src) {
|
|
286
|
-
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
287
|
-
extraOptions.isStatic = true
|
|
288
|
-
const issuerResource = addQuery(this.resource, { type: 'styles' }, true)
|
|
289
|
-
extraOptions.issuerFile = mpx.getExtractedFile(issuerResource)
|
|
290
|
-
}
|
|
291
299
|
output += getRequire('styles', style, extraOptions, i) + '\n'
|
|
292
300
|
})
|
|
293
301
|
} else if (ctorType === 'app' && mode === 'ali') {
|
|
@@ -298,7 +306,10 @@ module.exports = function (content) {
|
|
|
298
306
|
output += '/* json */\n'
|
|
299
307
|
// 给予json默认值, 确保生成json request以自动补全json
|
|
300
308
|
const json = parts.json || {}
|
|
301
|
-
output += getRequire('json', json, json.src && {
|
|
309
|
+
output += getRequire('json', json, json.src && {
|
|
310
|
+
...queryObj,
|
|
311
|
+
resourcePath
|
|
312
|
+
}) + '\n'
|
|
302
313
|
|
|
303
314
|
// script
|
|
304
315
|
output += '/* script */\n'
|
|
@@ -310,9 +321,12 @@ module.exports = function (content) {
|
|
|
310
321
|
if (scriptSrcMode) output += `global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
|
|
311
322
|
// 传递ctorType以补全js内容
|
|
312
323
|
const extraOptions = {
|
|
324
|
+
...script.src ? {
|
|
325
|
+
...queryObj,
|
|
326
|
+
resourcePath
|
|
327
|
+
} : null,
|
|
313
328
|
ctorType
|
|
314
329
|
}
|
|
315
|
-
if (script.src) extraOptions.resourcePath = resourcePath
|
|
316
330
|
output += getRequire('script', script, extraOptions) + '\n'
|
|
317
331
|
}
|
|
318
332
|
callback(null, output)
|
package/lib/native-loader.js
CHANGED
|
@@ -137,9 +137,10 @@ module.exports = function (content) {
|
|
|
137
137
|
const getRequireByType = (type) => {
|
|
138
138
|
const src = typeResourceMap[type]
|
|
139
139
|
const part = { src }
|
|
140
|
-
const extraOptions =
|
|
140
|
+
const extraOptions = {
|
|
141
|
+
...queryObj,
|
|
141
142
|
resourcePath
|
|
142
|
-
}
|
|
143
|
+
}
|
|
143
144
|
|
|
144
145
|
switch (type) {
|
|
145
146
|
case 'template':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.1-beta.
|
|
3
|
+
"version": "2.7.1-beta.8",
|
|
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": "1220be327d19323bbd05eeac10e24b4dd5add2c2"
|
|
84
84
|
}
|