@mpxjs/webpack-plugin 2.7.0-beta.7 → 2.7.0-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/index.js +24 -11
- package/lib/json-compiler/helper.js +4 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -49,6 +49,7 @@ const async = require('async')
|
|
|
49
49
|
const stringifyLoadersAndResource = require('./utils/stringify-loaders-resource')
|
|
50
50
|
const emitFile = require('./utils/emit-file')
|
|
51
51
|
const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
|
|
52
|
+
const isEmptyObject = require('./utils/is-empty-object')
|
|
52
53
|
|
|
53
54
|
const isProductionLikeMode = options => {
|
|
54
55
|
return options.mode === 'production' || !options.mode
|
|
@@ -359,18 +360,17 @@ class MpxWebpackPlugin {
|
|
|
359
360
|
|
|
360
361
|
let mpx
|
|
361
362
|
|
|
362
|
-
|
|
363
|
-
compiler.hooks.finishMake.tapAsync({
|
|
364
|
-
name: 'MpxWebpackPlugin',
|
|
365
|
-
stage: -1000
|
|
366
|
-
}, (compilation, callback) => {
|
|
363
|
+
const processSubpackagesEntriesMap = (compilation, callback) => {
|
|
367
364
|
const mpx = compilation.__mpx__
|
|
368
|
-
if (mpx && mpx.subpackagesEntriesMap) {
|
|
369
|
-
|
|
365
|
+
if (mpx && !isEmptyObject(mpx.subpackagesEntriesMap)) {
|
|
366
|
+
const subpackagesEntriesMap = mpx.subpackagesEntriesMap
|
|
367
|
+
// 执行分包队列前清空mpx.subpackagesEntriesMap
|
|
368
|
+
mpx.subpackagesEntriesMap = {}
|
|
369
|
+
async.eachOfSeries(subpackagesEntriesMap, (deps, packageRoot, callback) => {
|
|
370
370
|
mpx.currentPackageRoot = packageRoot
|
|
371
|
-
mpx.componentsMap[packageRoot] = {}
|
|
372
|
-
mpx.staticResourcesMap[packageRoot] = {}
|
|
373
|
-
mpx.subpackageModulesMap[packageRoot] = {}
|
|
371
|
+
mpx.componentsMap[packageRoot] = mpx.componentsMap[packageRoot] || {}
|
|
372
|
+
mpx.staticResourcesMap[packageRoot] = mpx.staticResourcesMap[packageRoot] || {}
|
|
373
|
+
mpx.subpackageModulesMap[packageRoot] = mpx.subpackageModulesMap[packageRoot] || {}
|
|
374
374
|
async.each(deps, (dep, callback) => {
|
|
375
375
|
dep.addEntry(compilation, (err, { resultPath }) => {
|
|
376
376
|
if (err) return callback(err)
|
|
@@ -378,10 +378,22 @@ class MpxWebpackPlugin {
|
|
|
378
378
|
callback()
|
|
379
379
|
})
|
|
380
380
|
}, callback)
|
|
381
|
-
},
|
|
381
|
+
}, (err) => {
|
|
382
|
+
if (err) return callback(err)
|
|
383
|
+
// 如果执行完当前队列后产生了新的分包执行队列(一般由异步分包组件造成),则继续执行
|
|
384
|
+
processSubpackagesEntriesMap(compilation, callback)
|
|
385
|
+
})
|
|
382
386
|
} else {
|
|
383
387
|
callback()
|
|
384
388
|
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// 构建分包队列,在finishMake钩子当中最先执行,stage传递-1000
|
|
392
|
+
compiler.hooks.finishMake.tapAsync({
|
|
393
|
+
name: 'MpxWebpackPlugin',
|
|
394
|
+
stage: -1000
|
|
395
|
+
}, (compilation, callback) => {
|
|
396
|
+
processSubpackagesEntriesMap(compilation, callback)
|
|
385
397
|
})
|
|
386
398
|
|
|
387
399
|
compiler.hooks.compilation.tap('MpxWebpackPlugin ', (compilation, { normalModuleFactory }) => {
|
|
@@ -597,6 +609,7 @@ class MpxWebpackPlugin {
|
|
|
597
609
|
if (currentResourceMap[resourcePath] === outputPath) {
|
|
598
610
|
alreadyOutputed = true
|
|
599
611
|
} else {
|
|
612
|
+
// todo 用outputPathMap来检测冲突
|
|
600
613
|
// 输出冲突检测,如果存在输出路径冲突,对输出路径进行重命名
|
|
601
614
|
for (let key in currentResourceMap) {
|
|
602
615
|
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
@@ -14,6 +14,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
14
14
|
const publicPath = loaderContext._compilation.outputOptions.publicPath || ''
|
|
15
15
|
const pathHash = mpx.pathHash
|
|
16
16
|
const getOutputPath = mpx.getOutputPath
|
|
17
|
+
const mode = mpx.mode
|
|
17
18
|
|
|
18
19
|
const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
|
|
19
20
|
const urlToRequest = r => loaderUtils.urlToRequest(r)
|
|
@@ -45,7 +46,9 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
45
46
|
|
|
46
47
|
resolve(context, component, loaderContext, (err, resource, info) => {
|
|
47
48
|
if (err) return callback(err)
|
|
48
|
-
const resourcePath = parseRequest(resource)
|
|
49
|
+
const { resourcePath, queryObj } = parseRequest(resource)
|
|
50
|
+
// 目前只有微信支持分包异步化
|
|
51
|
+
if (queryObj.root && mode === 'wx') tarRoot = queryObj.root
|
|
49
52
|
const parsed = path.parse(resourcePath)
|
|
50
53
|
const ext = parsed.ext
|
|
51
54
|
const resourceName = path.join(parsed.dir, parsed.name)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.0-beta.
|
|
3
|
+
"version": "2.7.0-beta.8",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"@types/babel-traverse": "^6.25.4",
|
|
78
78
|
"@types/babel-types": "^7.0.4"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "73247d266ae7380b88295208d645f85b9dd72398"
|
|
81
81
|
}
|