@mpxjs/webpack-plugin 2.8.40-beta.0 → 2.8.41
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
2
|
const parseRequest = require('../utils/parse-request')
|
|
3
3
|
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
4
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
4
5
|
|
|
5
6
|
class ResolveDependency extends NullDependency {
|
|
6
7
|
constructor (resource, packageName, issuerResource, range) {
|
|
@@ -22,39 +23,29 @@ class ResolveDependency extends NullDependency {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
getResolved () {
|
|
25
|
-
const { resource, packageName, compilation } = this
|
|
26
|
+
const { resource, packageName, compilation, issuerResource } = this
|
|
26
27
|
if (!compilation) return ''
|
|
27
28
|
const mpx = compilation.__mpx__
|
|
28
29
|
if (!mpx) return ''
|
|
29
|
-
const { pagesMap, componentsMap, staticResourcesMap } = mpx
|
|
30
|
+
const { pagesMap, componentsMap, staticResourcesMap, partialCompile } = mpx
|
|
30
31
|
const { resourcePath } = parseRequest(resource)
|
|
31
32
|
const currentComponentsMap = componentsMap[packageName]
|
|
32
33
|
const mainComponentsMap = componentsMap.main
|
|
33
34
|
const currentStaticResourcesMap = staticResourcesMap[packageName]
|
|
34
35
|
const mainStaticResourcesMap = staticResourcesMap.main
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { partialCompileFilteredPagesMap } = mpx
|
|
43
|
-
const { resourcePath } = parseRequest(resource)
|
|
44
|
-
return partialCompileFilteredPagesMap[resourcePath]
|
|
36
|
+
const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
|
|
37
|
+
if (!resolveResult) {
|
|
38
|
+
if (!partialCompile || matchCondition(resourcePath, partialCompile)) {
|
|
39
|
+
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return resolveResult
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
// resolved可能会动态变更,需用此更新hash
|
|
48
46
|
updateHash (hash, context) {
|
|
49
47
|
this.resolved = this.getResolved()
|
|
50
|
-
|
|
51
|
-
if (this.resolved) {
|
|
52
|
-
hash.update(this.resolved)
|
|
53
|
-
} else {
|
|
54
|
-
if (!this.isPartialCompileFilteredPage(resource)) {
|
|
55
|
-
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
56
|
-
}
|
|
57
|
-
}
|
|
48
|
+
hash.update(this.resolved)
|
|
58
49
|
super.updateHash(hash, context)
|
|
59
50
|
}
|
|
60
51
|
|
package/lib/index.js
CHANGED
|
@@ -383,8 +383,8 @@ class MpxWebpackPlugin {
|
|
|
383
383
|
if (this.options.partialCompile) {
|
|
384
384
|
function isResolvingPage (obj) {
|
|
385
385
|
// valid query should start with '?'
|
|
386
|
-
const query = obj.query || '?'
|
|
387
|
-
return
|
|
386
|
+
const query = parseQuery(obj.query || '?')
|
|
387
|
+
return query.isPage && !query.type
|
|
388
388
|
}
|
|
389
389
|
// new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
|
|
390
390
|
compiler.resolverFactory.hooks.resolver.intercept({
|
|
@@ -394,9 +394,13 @@ class MpxWebpackPlugin {
|
|
|
394
394
|
name: 'MpxPartialCompilePlugin',
|
|
395
395
|
stage: -100
|
|
396
396
|
}, (obj, resolverContext, callback) => {
|
|
397
|
+
if (obj.path.startsWith(require.resolve('./json-compiler/default-page.mpx'))) {
|
|
398
|
+
return callback(null, obj)
|
|
399
|
+
}
|
|
397
400
|
if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
|
|
398
|
-
|
|
399
|
-
obj.
|
|
401
|
+
const infix = obj.query ? '&' : '?'
|
|
402
|
+
obj.query += `${infix}resourcePath=${obj.path}`
|
|
403
|
+
obj.path = require.resolve('./json-compiler/default-page.mpx')
|
|
400
404
|
}
|
|
401
405
|
callback(null, obj)
|
|
402
406
|
})
|
|
@@ -617,7 +621,7 @@ class MpxWebpackPlugin {
|
|
|
617
621
|
removedChunks: [],
|
|
618
622
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
619
623
|
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
620
|
-
|
|
624
|
+
partialCompile: this.options.partialCompile,
|
|
621
625
|
pathHash: (resourcePath) => {
|
|
622
626
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
623
627
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -6,7 +6,6 @@ const parseRequest = require('../utils/parse-request')
|
|
|
6
6
|
const addQuery = require('../utils/add-query')
|
|
7
7
|
const loaderUtils = require('loader-utils')
|
|
8
8
|
const resolve = require('../utils/resolve')
|
|
9
|
-
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
10
9
|
|
|
11
10
|
module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
|
|
12
11
|
const mpx = loaderContext.getMpx()
|
|
@@ -103,13 +102,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
103
102
|
page = addQuery(page, { isPage: true })
|
|
104
103
|
resolve(context, page, loaderContext, (err, resource) => {
|
|
105
104
|
if (err) {
|
|
106
|
-
|
|
107
|
-
const defaultPage = require.resolve('./default-page.mpx') + `?resourcePath=${context}/${tarRoot}/pages/index.mpx`
|
|
108
|
-
resource = defaultPage
|
|
109
|
-
aliasPath = ''
|
|
110
|
-
} else {
|
|
111
|
-
return callback(err)
|
|
112
|
-
}
|
|
105
|
+
return callback(err)
|
|
113
106
|
}
|
|
114
107
|
const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
|
|
115
108
|
const ext = path.extname(resourcePath)
|
|
@@ -133,7 +126,8 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
133
126
|
const key = [resourcePath, outputPath, tarRoot].join('|')
|
|
134
127
|
callback(null, entry, {
|
|
135
128
|
isFirst,
|
|
136
|
-
key
|
|
129
|
+
key,
|
|
130
|
+
resource
|
|
137
131
|
})
|
|
138
132
|
})
|
|
139
133
|
}
|
|
@@ -221,14 +221,20 @@ module.exports = function (content) {
|
|
|
221
221
|
const localPages = []
|
|
222
222
|
const subPackagesCfg = {}
|
|
223
223
|
const pageKeySet = new Set()
|
|
224
|
-
|
|
224
|
+
const defaultPagePath = require.resolve('./default-page.mpx')
|
|
225
225
|
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
226
226
|
if (pages) {
|
|
227
|
+
const pagesCache = []
|
|
227
228
|
async.each(pages, (page, callback) => {
|
|
228
|
-
processPage(page, context, tarRoot, (err, entry, { isFirst, key } = {}) => {
|
|
229
|
+
processPage(page, context, tarRoot, (err, entry, { isFirst, key, resource } = {}) => {
|
|
229
230
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
230
231
|
if (pageKeySet.has(key)) return callback()
|
|
232
|
+
if (resource.startsWith(defaultPagePath)) {
|
|
233
|
+
pagesCache.push(entry)
|
|
234
|
+
return callback()
|
|
235
|
+
}
|
|
231
236
|
pageKeySet.add(key)
|
|
237
|
+
|
|
232
238
|
if (tarRoot && subPackagesCfg) {
|
|
233
239
|
subPackagesCfg[tarRoot].pages.push(entry)
|
|
234
240
|
} else {
|
|
@@ -241,7 +247,18 @@ module.exports = function (content) {
|
|
|
241
247
|
}
|
|
242
248
|
callback()
|
|
243
249
|
})
|
|
244
|
-
},
|
|
250
|
+
}, () => {
|
|
251
|
+
if (tarRoot && subPackagesCfg) {
|
|
252
|
+
if (!subPackagesCfg[tarRoot].pages.length && pagesCache[0]) {
|
|
253
|
+
subPackagesCfg[tarRoot].pages.push(pagesCache[0])
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
if (!localPages.length && pagesCache[0]) {
|
|
257
|
+
localPages.push(pagesCache[0])
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
callback()
|
|
261
|
+
})
|
|
245
262
|
} else {
|
|
246
263
|
callback()
|
|
247
264
|
}
|
|
@@ -577,10 +594,12 @@ module.exports = function (content) {
|
|
|
577
594
|
for (const root in subPackagesCfg) {
|
|
578
595
|
const subPackageCfg = subPackagesCfg[root]
|
|
579
596
|
// 分包不存在 pages,输出 subPackages 字段会报错
|
|
580
|
-
if (
|
|
581
|
-
json.subPackages
|
|
597
|
+
if (subPackageCfg.pages.length) {
|
|
598
|
+
if (!json.subPackages) {
|
|
599
|
+
json.subPackages = []
|
|
600
|
+
}
|
|
601
|
+
json.subPackages.push(subPackageCfg)
|
|
582
602
|
}
|
|
583
|
-
json.subPackages.push(subPackageCfg)
|
|
584
603
|
}
|
|
585
604
|
const processOutput = (output) => {
|
|
586
605
|
output = processDynamicEntry(output)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.41",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14.14.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "f3bfd9bf76756bebe92204e4b87b182b1b5b5502"
|
|
86
86
|
}
|