@mpxjs/webpack-plugin 2.8.40 → 2.8.42
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/ResolveDependency.js +11 -9
- package/lib/index.js +29 -2
- package/lib/json-compiler/default-page.mpx +3 -0
- package/lib/json-compiler/helper.js +5 -2
- package/lib/json-compiler/index.js +30 -10
- package/lib/loader.js +2 -9
- package/lib/native-loader.js +3 -8
- package/lib/platform/json/wx/index.js +21 -0
- package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
- package/lib/platform/template/wx/component-config/index.js +2 -2
- package/lib/platform/template/wx/index.js +9 -9
- package/package.json +2 -2
- package/lib/partial-compile/index.js +0 -35
|
@@ -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,28 +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
|
+
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
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
// resolved可能会动态变更,需用此更新hash
|
|
39
46
|
updateHash (hash, context) {
|
|
40
47
|
this.resolved = this.getResolved()
|
|
41
|
-
|
|
42
|
-
if (this.resolved) {
|
|
43
|
-
hash.update(this.resolved)
|
|
44
|
-
} else {
|
|
45
|
-
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
46
|
-
}
|
|
48
|
+
hash.update(this.resolved)
|
|
47
49
|
super.updateHash(hash, context)
|
|
48
50
|
}
|
|
49
51
|
|
package/lib/index.js
CHANGED
|
@@ -38,7 +38,6 @@ const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
|
|
|
38
38
|
const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
|
|
39
39
|
const RecordVueContentDependency = require('./dependencies/RecordVueContentDependency')
|
|
40
40
|
const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
|
|
41
|
-
const PartialCompilePlugin = require('./partial-compile/index')
|
|
42
41
|
const fixRelative = require('./utils/fix-relative')
|
|
43
42
|
const parseRequest = require('./utils/parse-request')
|
|
44
43
|
const { matchCondition } = require('./utils/match-condition')
|
|
@@ -55,6 +54,7 @@ const jsonThemeCompilerPath = normalize.lib('json-compiler/theme')
|
|
|
55
54
|
const jsonPluginCompilerPath = normalize.lib('json-compiler/plugin')
|
|
56
55
|
const extractorPath = normalize.lib('extractor')
|
|
57
56
|
const async = require('async')
|
|
57
|
+
const { parseQuery } = require('loader-utils')
|
|
58
58
|
const stringifyLoadersAndResource = require('./utils/stringify-loaders-resource')
|
|
59
59
|
const emitFile = require('./utils/emit-file')
|
|
60
60
|
const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
|
|
@@ -381,7 +381,33 @@ class MpxWebpackPlugin {
|
|
|
381
381
|
let mpx
|
|
382
382
|
|
|
383
383
|
if (this.options.partialCompile) {
|
|
384
|
-
|
|
384
|
+
function isResolvingPage (obj) {
|
|
385
|
+
// valid query should start with '?'
|
|
386
|
+
const query = parseQuery(obj.query || '?')
|
|
387
|
+
return query.isPage && !query.type
|
|
388
|
+
}
|
|
389
|
+
// new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
|
|
390
|
+
compiler.resolverFactory.hooks.resolver.intercept({
|
|
391
|
+
factory: (type, hook) => {
|
|
392
|
+
hook.tap('MpxPartialCompilePlugin', (resolver) => {
|
|
393
|
+
resolver.hooks.result.tapAsync({
|
|
394
|
+
name: 'MpxPartialCompilePlugin',
|
|
395
|
+
stage: -100
|
|
396
|
+
}, (obj, resolverContext, callback) => {
|
|
397
|
+
if (obj.path.startsWith(require.resolve('./json-compiler/default-page.mpx'))) {
|
|
398
|
+
return callback(null, obj)
|
|
399
|
+
}
|
|
400
|
+
if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
|
|
401
|
+
const infix = obj.query ? '&' : '?'
|
|
402
|
+
obj.query += `${infix}resourcePath=${obj.path}`
|
|
403
|
+
obj.path = require.resolve('./json-compiler/default-page.mpx')
|
|
404
|
+
}
|
|
405
|
+
callback(null, obj)
|
|
406
|
+
})
|
|
407
|
+
})
|
|
408
|
+
return hook
|
|
409
|
+
}
|
|
410
|
+
})
|
|
385
411
|
}
|
|
386
412
|
|
|
387
413
|
const getPackageCacheGroup = packageName => {
|
|
@@ -595,6 +621,7 @@ class MpxWebpackPlugin {
|
|
|
595
621
|
removedChunks: [],
|
|
596
622
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
597
623
|
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
624
|
+
partialCompile: this.options.partialCompile,
|
|
598
625
|
pathHash: (resourcePath) => {
|
|
599
626
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
600
627
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -101,7 +101,9 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
101
101
|
// 增加 page 标识
|
|
102
102
|
page = addQuery(page, { isPage: true })
|
|
103
103
|
resolve(context, page, loaderContext, (err, resource) => {
|
|
104
|
-
if (err)
|
|
104
|
+
if (err) {
|
|
105
|
+
return callback(err)
|
|
106
|
+
}
|
|
105
107
|
const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
|
|
106
108
|
const ext = path.extname(resourcePath)
|
|
107
109
|
let outputPath
|
|
@@ -124,7 +126,8 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
124
126
|
const key = [resourcePath, outputPath, tarRoot].join('|')
|
|
125
127
|
callback(null, entry, {
|
|
126
128
|
isFirst,
|
|
127
|
-
key
|
|
129
|
+
key,
|
|
130
|
+
resource
|
|
128
131
|
})
|
|
129
132
|
})
|
|
130
133
|
}
|
|
@@ -177,14 +177,14 @@ module.exports = function (content) {
|
|
|
177
177
|
type: 'json',
|
|
178
178
|
waterfall: true,
|
|
179
179
|
warn: emitWarning,
|
|
180
|
-
error: emitError
|
|
180
|
+
error: emitError,
|
|
181
|
+
data: {
|
|
182
|
+
// polyfill global usingComponents & record globalComponents
|
|
183
|
+
globalComponents: mpx.usingComponents
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
186
|
if (!isApp) {
|
|
183
187
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
184
|
-
// polyfill global usingComponents
|
|
185
|
-
rulesRunnerOptions.data = {
|
|
186
|
-
globalComponents: mpx.usingComponents
|
|
187
|
-
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
@@ -193,9 +193,12 @@ module.exports = function (content) {
|
|
|
193
193
|
rulesRunner(json)
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
if (isApp
|
|
196
|
+
if (isApp) {
|
|
197
|
+
Object.assign(mpx.usingComponents, json.usingComponents)
|
|
197
198
|
// 在 rulesRunner 运行后保存全局注册组件
|
|
198
|
-
|
|
199
|
+
// todo 其余地方在使用mpx.usingComponents时存在缓存问题,要规避该问题需要在所有使用mpx.usingComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
|
|
200
|
+
// todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
|
|
201
|
+
this._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, this.context))
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
const processComponents = (components, context, callback) => {
|
|
@@ -221,14 +224,20 @@ module.exports = function (content) {
|
|
|
221
224
|
const localPages = []
|
|
222
225
|
const subPackagesCfg = {}
|
|
223
226
|
const pageKeySet = new Set()
|
|
224
|
-
|
|
227
|
+
const defaultPagePath = require.resolve('./default-page.mpx')
|
|
225
228
|
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
226
229
|
if (pages) {
|
|
230
|
+
const pagesCache = []
|
|
227
231
|
async.each(pages, (page, callback) => {
|
|
228
|
-
processPage(page, context, tarRoot, (err, entry, { isFirst, key } = {}) => {
|
|
232
|
+
processPage(page, context, tarRoot, (err, entry, { isFirst, key, resource } = {}) => {
|
|
229
233
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
230
234
|
if (pageKeySet.has(key)) return callback()
|
|
235
|
+
if (resource.startsWith(defaultPagePath)) {
|
|
236
|
+
pagesCache.push(entry)
|
|
237
|
+
return callback()
|
|
238
|
+
}
|
|
231
239
|
pageKeySet.add(key)
|
|
240
|
+
|
|
232
241
|
if (tarRoot && subPackagesCfg) {
|
|
233
242
|
subPackagesCfg[tarRoot].pages.push(entry)
|
|
234
243
|
} else {
|
|
@@ -241,7 +250,18 @@ module.exports = function (content) {
|
|
|
241
250
|
}
|
|
242
251
|
callback()
|
|
243
252
|
})
|
|
244
|
-
},
|
|
253
|
+
}, () => {
|
|
254
|
+
if (tarRoot && subPackagesCfg) {
|
|
255
|
+
if (!subPackagesCfg[tarRoot].pages.length && pagesCache[0]) {
|
|
256
|
+
subPackagesCfg[tarRoot].pages.push(pagesCache[0])
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
if (!localPages.length && pagesCache[0]) {
|
|
260
|
+
localPages.push(pagesCache[0])
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
callback()
|
|
264
|
+
})
|
|
245
265
|
} else {
|
|
246
266
|
callback()
|
|
247
267
|
}
|
package/lib/loader.js
CHANGED
|
@@ -120,7 +120,6 @@ module.exports = function (content) {
|
|
|
120
120
|
|
|
121
121
|
let usingComponents = [].concat(Object.keys(mpx.usingComponents))
|
|
122
122
|
let componentPlaceholder = []
|
|
123
|
-
|
|
124
123
|
let componentGenerics = {}
|
|
125
124
|
|
|
126
125
|
if (parts.json && parts.json.content) {
|
|
@@ -134,18 +133,12 @@ module.exports = function (content) {
|
|
|
134
133
|
}
|
|
135
134
|
if (!isApp) {
|
|
136
135
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
137
|
-
// polyfill global usingComponents
|
|
138
|
-
// 预读json时无需注入polyfill全局组件
|
|
139
|
-
// rulesRunnerOptions.data = {
|
|
140
|
-
// globalComponents: mpx.usingComponents
|
|
141
|
-
// }
|
|
142
136
|
}
|
|
143
|
-
|
|
137
|
+
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
144
138
|
try {
|
|
145
139
|
const ret = JSON5.parse(parts.json.content)
|
|
140
|
+
if (rulesRunner) rulesRunner(ret)
|
|
146
141
|
if (ret.usingComponents) {
|
|
147
|
-
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
148
|
-
if (rulesRunner) rulesRunner(ret)
|
|
149
142
|
usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
|
|
150
143
|
}
|
|
151
144
|
if (ret.componentPlaceholder) {
|
package/lib/native-loader.js
CHANGED
|
@@ -137,6 +137,7 @@ module.exports = function (content) {
|
|
|
137
137
|
} catch (e) {
|
|
138
138
|
return callback(e)
|
|
139
139
|
}
|
|
140
|
+
let usingComponents = Object.keys(mpx.usingComponents)
|
|
140
141
|
const rulesRunnerOptions = {
|
|
141
142
|
mode,
|
|
142
143
|
srcMode,
|
|
@@ -147,16 +148,10 @@ module.exports = function (content) {
|
|
|
147
148
|
}
|
|
148
149
|
if (!isApp) {
|
|
149
150
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
150
|
-
// polyfill global usingComponents
|
|
151
|
-
// 预读json时无需注入polyfill全局组件
|
|
152
|
-
// rulesRunnerOptions.data = {
|
|
153
|
-
// globalComponents: mpx.usingComponents
|
|
154
|
-
// }
|
|
155
151
|
}
|
|
156
|
-
|
|
152
|
+
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
153
|
+
if (rulesRunner) rulesRunner(json)
|
|
157
154
|
if (json.usingComponents) {
|
|
158
|
-
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
159
|
-
if (rulesRunner) rulesRunner(json)
|
|
160
155
|
usingComponents = usingComponents.concat(Object.keys(json.usingComponents))
|
|
161
156
|
}
|
|
162
157
|
const {
|
|
@@ -70,6 +70,13 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
70
70
|
return input
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function fillGlobalComponents (input, { globalComponents }) {
|
|
74
|
+
if (globalComponents) {
|
|
75
|
+
Object.assign(globalComponents, input.usingComponents)
|
|
76
|
+
}
|
|
77
|
+
return input
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
// 处理 ali swan 的组件名大写字母转连字符:WordExample/wordExample -> word-example
|
|
74
81
|
function componentNameCapitalToHyphen (type) {
|
|
75
82
|
return function (input) {
|
|
@@ -318,6 +325,20 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
318
325
|
tt: deletePath(),
|
|
319
326
|
jd: deletePath(true)
|
|
320
327
|
},
|
|
328
|
+
{
|
|
329
|
+
test: 'usingComponents',
|
|
330
|
+
ali: componentNameCapitalToHyphen('usingComponents'),
|
|
331
|
+
swan: componentNameCapitalToHyphen('usingComponents')
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
test: 'usingComponents',
|
|
335
|
+
// todo ali 2.0已支持全局组件,待移除
|
|
336
|
+
ali: fillGlobalComponents,
|
|
337
|
+
qq: fillGlobalComponents,
|
|
338
|
+
swan: fillGlobalComponents,
|
|
339
|
+
tt: fillGlobalComponents,
|
|
340
|
+
jd: fillGlobalComponents
|
|
341
|
+
},
|
|
321
342
|
{
|
|
322
343
|
test: 'usingComponents',
|
|
323
344
|
// todo ali 2.0已支持全局组件,待移除
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
const { capitalToHyphen } = require('../../../../utils/string')
|
|
2
2
|
|
|
3
3
|
module.exports = function () {
|
|
4
|
-
function convertTagName (name) {
|
|
5
|
-
return capitalToHyphen(name)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
4
|
return {
|
|
9
5
|
// tag name contains capital letters
|
|
10
6
|
test: /[A-Z]/,
|
|
11
|
-
ali:
|
|
12
|
-
swan:
|
|
7
|
+
ali: capitalToHyphen,
|
|
8
|
+
swan: capitalToHyphen
|
|
13
9
|
}
|
|
14
10
|
}
|
|
@@ -8,7 +8,7 @@ const checkbox = require('./checkbox')
|
|
|
8
8
|
const coverImage = require('./cover-image')
|
|
9
9
|
const coverView = require('./cover-view')
|
|
10
10
|
const form = require('./form')
|
|
11
|
-
const
|
|
11
|
+
const hyphenTagName = require('./hypen-tag-name')
|
|
12
12
|
const icon = require('./icon')
|
|
13
13
|
const image = require('./image')
|
|
14
14
|
const input = require('./input')
|
|
@@ -118,7 +118,7 @@ module.exports = function getComponentConfigs ({ warn, error }) {
|
|
|
118
118
|
camera({ print }),
|
|
119
119
|
livePlayer({ print }),
|
|
120
120
|
livePusher({ print }),
|
|
121
|
-
|
|
121
|
+
hyphenTagName({ print }),
|
|
122
122
|
component()
|
|
123
123
|
]
|
|
124
124
|
}
|
|
@@ -190,16 +190,16 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
190
190
|
}
|
|
191
191
|
const styleBinding = []
|
|
192
192
|
el.isStyleParsed = true
|
|
193
|
-
|
|
193
|
+
// 不过滤的话每一个属性都要 parse
|
|
194
|
+
el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
|
|
194
195
|
const parsed = parseMustache(item.value)
|
|
195
|
-
if (item.name === 'style') {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
styleBinding.push(parseMustache(item.value).result)
|
|
196
|
+
if (item.name === 'wx:style') {
|
|
197
|
+
styleBinding.push(parsed.result)
|
|
198
|
+
// item.name === 'style'
|
|
199
|
+
} else if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
|
|
200
|
+
styleBinding.push(parsed.result)
|
|
201
|
+
} else {
|
|
202
|
+
styleBinding.push(JSON.stringify(item.value))
|
|
203
203
|
}
|
|
204
204
|
})
|
|
205
205
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.42",
|
|
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": "a0d7f0171b8e4535f1962bdb7415fec0d25abe93"
|
|
86
86
|
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const { matchCondition } = require('../utils/match-condition')
|
|
2
|
-
const { parseQuery } = require('loader-utils')
|
|
3
|
-
|
|
4
|
-
class MpxPartialCompilePlugin {
|
|
5
|
-
constructor (condition) {
|
|
6
|
-
this.condition = condition
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
isResolvingPage (obj) {
|
|
10
|
-
// valid query should start with '?'
|
|
11
|
-
const query = obj.query || '?'
|
|
12
|
-
return parseQuery(query).isPage
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
apply (compiler) {
|
|
16
|
-
compiler.resolverFactory.hooks.resolver.intercept({
|
|
17
|
-
factory: (type, hook) => {
|
|
18
|
-
hook.tap('MpxPartialCompilePlugin', (resolver) => {
|
|
19
|
-
resolver.hooks.result.tapAsync({
|
|
20
|
-
name: 'MpxPartialCompilePlugin',
|
|
21
|
-
stage: -100
|
|
22
|
-
}, (obj, resolverContext, callback) => {
|
|
23
|
-
if (this.isResolvingPage(obj) && !matchCondition(obj.path, this.condition)) {
|
|
24
|
-
obj.path = false
|
|
25
|
-
}
|
|
26
|
-
callback(null, obj)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
return hook
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = MpxPartialCompilePlugin
|