@mpxjs/webpack-plugin 2.7.52 → 2.8.0-beta.1
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/.DS_Store +0 -0
- package/lib/config.js +24 -24
- package/lib/dependencies/CommonJsVariableDependency.js +1 -1
- package/lib/dependencies/DynamicEntryDependency.js +18 -11
- package/lib/extractor.js +1 -1
- package/lib/helpers.js +3 -1
- package/lib/index.js +24 -21
- package/lib/json-compiler/helper.js +1 -1
- package/lib/json-compiler/index.js +17 -17
- package/lib/json-compiler/plugin.js +3 -2
- package/lib/json-compiler/theme.js +1 -1
- package/lib/loader.js +3 -3
- package/lib/native-loader.js +1 -1
- package/lib/platform/json/normalize-test.js +3 -1
- package/lib/platform/run-rules.js +2 -2
- package/lib/platform/template/wx/component-config/camera.js +3 -3
- package/lib/platform/template/wx/component-config/canvas.js +5 -5
- package/lib/platform/template/wx/component-config/map.js +5 -5
- package/lib/platform/template/wx/component-config/navigator.js +7 -7
- package/lib/platform/template/wx/component-config/progress.js +4 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +3 -3
- package/lib/platform/template/wx/component-config/slider.js +6 -6
- package/lib/platform/template/wx/component-config/swiper.js +2 -2
- package/lib/platform/template/wx/component-config/video.js +4 -4
- package/lib/platform/template/wx/component-config/view.js +4 -4
- package/lib/platform/template/wx/index.js +45 -13
- package/lib/resolver/PackageEntryPlugin.js +1 -1
- package/lib/runtime/components/web/filterTag.js +6 -6
- package/lib/runtime/components/web/getInnerListeners.js +1 -1
- package/lib/runtime/components/web/mpx-button.vue +0 -1
- package/lib/runtime/components/web/mpx-icon.vue +1 -1
- package/lib/runtime/components/web/mpx-keep-alive.vue +2 -2
- package/lib/runtime/components/web/mpx-picker.vue +1 -1
- package/lib/runtime/components/web/mpx-progress.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
- package/lib/runtime/env.js +1 -0
- package/lib/runtime/i18n.wxs +44 -81
- package/lib/runtime/optionProcessor.d.ts +0 -4
- package/lib/runtime/optionProcessor.js +15 -13
- package/lib/runtime/stringify.wxs +3 -3
- package/lib/runtime/swanHelper.wxs +2 -2
- package/lib/runtime/{components/web/util.js → utils.js} +8 -5
- package/lib/script-setup-compiler/index.js +1163 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/rpx.js +1 -1
- package/lib/style-compiler/plugins/vw.js +6 -4
- package/lib/template-compiler/bind-this.js +5 -5
- package/lib/template-compiler/compiler.js +122 -179
- package/lib/template-compiler/index.js +3 -3
- package/lib/utils/add-query.js +2 -1
- package/lib/utils/gen-component-tag.js +1 -1
- package/lib/utils/has-own.js +5 -0
- package/lib/utils/is-empty-object.js +2 -1
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/{index.js → process-defs.js} +3 -10
- package/lib/utils/stringify-query.js +23 -21
- package/lib/web/processJSON.js +5 -5
- package/lib/web/processScript.js +16 -19
- package/lib/web/processTemplate.js +1 -1
- package/lib/wxml/loader.js +3 -3
- package/lib/wxs/i18n-loader.js +4 -11
- package/lib/wxs/pre-loader.js +51 -44
- package/lib/wxss/compile-exports.js +4 -4
- package/lib/wxss/createResolver.js +3 -3
- package/lib/wxss/css-base.js +13 -13
- package/lib/wxss/getLocalIdent.js +5 -4
- package/lib/wxss/loader.js +1 -1
- package/lib/wxss/localsLoader.js +14 -14
- package/lib/wxss/processCss.js +10 -7
- package/package.json +2 -2
- package/lib/utils/env.js +0 -4
- package/lib/utils/parse-asset.js +0 -195
package/lib/.DS_Store
ADDED
|
Binary file
|
package/lib/config.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = {
|
|
|
13
13
|
},
|
|
14
14
|
event: {
|
|
15
15
|
parseEvent (attr) {
|
|
16
|
-
|
|
16
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
17
17
|
if (match) {
|
|
18
18
|
return {
|
|
19
19
|
prefix: match[1],
|
|
@@ -29,8 +29,8 @@ module.exports = {
|
|
|
29
29
|
defaultModelEvent: 'input',
|
|
30
30
|
defaultModelValuePath: 'value',
|
|
31
31
|
shallowStringify (obj) {
|
|
32
|
-
|
|
33
|
-
for (
|
|
32
|
+
const arr = []
|
|
33
|
+
for (const key in obj) {
|
|
34
34
|
let value = obj[key]
|
|
35
35
|
if (Array.isArray(value)) {
|
|
36
36
|
value = `[${value.join(',')}]`
|
|
@@ -83,7 +83,7 @@ module.exports = {
|
|
|
83
83
|
},
|
|
84
84
|
event: {
|
|
85
85
|
parseEvent (attr) {
|
|
86
|
-
|
|
86
|
+
const match = /^(on|catch)([A-Z].*?)(?:\.(.*))?$/.exec(attr)
|
|
87
87
|
if (match) {
|
|
88
88
|
return {
|
|
89
89
|
prefix: match[1],
|
|
@@ -103,8 +103,8 @@ module.exports = {
|
|
|
103
103
|
defaultModelEvent: 'input',
|
|
104
104
|
defaultModelValuePath: 'value',
|
|
105
105
|
shallowStringify (obj) {
|
|
106
|
-
|
|
107
|
-
for (
|
|
106
|
+
const arr = []
|
|
107
|
+
for (const key in obj) {
|
|
108
108
|
let value = obj[key]
|
|
109
109
|
if (Array.isArray(value)) {
|
|
110
110
|
value = `[${value.join(',')}]`
|
|
@@ -155,7 +155,7 @@ module.exports = {
|
|
|
155
155
|
},
|
|
156
156
|
event: {
|
|
157
157
|
parseEvent (attr) {
|
|
158
|
-
|
|
158
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
159
159
|
if (match) {
|
|
160
160
|
return {
|
|
161
161
|
prefix: match[1],
|
|
@@ -171,8 +171,8 @@ module.exports = {
|
|
|
171
171
|
defaultModelEvent: 'input',
|
|
172
172
|
defaultModelValuePath: 'value',
|
|
173
173
|
shallowStringify (obj) {
|
|
174
|
-
|
|
175
|
-
for (
|
|
174
|
+
const arr = []
|
|
175
|
+
for (const key in obj) {
|
|
176
176
|
let value = obj[key]
|
|
177
177
|
if (Array.isArray(value)) {
|
|
178
178
|
value = `[${value.join(',')}]`
|
|
@@ -222,7 +222,7 @@ module.exports = {
|
|
|
222
222
|
},
|
|
223
223
|
event: {
|
|
224
224
|
parseEvent (attr) {
|
|
225
|
-
|
|
225
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
226
226
|
if (match) {
|
|
227
227
|
return {
|
|
228
228
|
prefix: match[1],
|
|
@@ -238,8 +238,8 @@ module.exports = {
|
|
|
238
238
|
defaultModelEvent: 'input',
|
|
239
239
|
defaultModelValuePath: 'value',
|
|
240
240
|
shallowStringify (obj) {
|
|
241
|
-
|
|
242
|
-
for (
|
|
241
|
+
const arr = []
|
|
242
|
+
for (const key in obj) {
|
|
243
243
|
let value = obj[key]
|
|
244
244
|
if (Array.isArray(value)) {
|
|
245
245
|
value = `[${value.join(',')}]`
|
|
@@ -289,7 +289,7 @@ module.exports = {
|
|
|
289
289
|
},
|
|
290
290
|
event: {
|
|
291
291
|
parseEvent (attr) {
|
|
292
|
-
|
|
292
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
293
293
|
if (match) {
|
|
294
294
|
return {
|
|
295
295
|
prefix: match[1],
|
|
@@ -305,8 +305,8 @@ module.exports = {
|
|
|
305
305
|
defaultModelEvent: 'input',
|
|
306
306
|
defaultModelValuePath: 'value',
|
|
307
307
|
shallowStringify (obj) {
|
|
308
|
-
|
|
309
|
-
for (
|
|
308
|
+
const arr = []
|
|
309
|
+
for (const key in obj) {
|
|
310
310
|
let value = obj[key]
|
|
311
311
|
if (Array.isArray(value)) {
|
|
312
312
|
value = `[${value.join(',')}]`
|
|
@@ -370,7 +370,7 @@ module.exports = {
|
|
|
370
370
|
},
|
|
371
371
|
event: {
|
|
372
372
|
parseEvent (attr) {
|
|
373
|
-
|
|
373
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
374
374
|
if (match) {
|
|
375
375
|
return {
|
|
376
376
|
prefix: match[1],
|
|
@@ -386,8 +386,8 @@ module.exports = {
|
|
|
386
386
|
defaultModelEvent: 'input',
|
|
387
387
|
defaultModelValuePath: 'value',
|
|
388
388
|
shallowStringify (obj) {
|
|
389
|
-
|
|
390
|
-
for (
|
|
389
|
+
const arr = []
|
|
390
|
+
for (const key in obj) {
|
|
391
391
|
let value = obj[key]
|
|
392
392
|
if (Array.isArray(value)) {
|
|
393
393
|
value = `[${value.join(',')}]`
|
|
@@ -437,7 +437,7 @@ module.exports = {
|
|
|
437
437
|
},
|
|
438
438
|
event: {
|
|
439
439
|
parseEvent (attr) {
|
|
440
|
-
|
|
440
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
441
441
|
if (match) {
|
|
442
442
|
return {
|
|
443
443
|
prefix: match[1],
|
|
@@ -453,8 +453,8 @@ module.exports = {
|
|
|
453
453
|
defaultModelEvent: 'input',
|
|
454
454
|
defaultModelValuePath: 'value',
|
|
455
455
|
shallowStringify (obj) {
|
|
456
|
-
|
|
457
|
-
for (
|
|
456
|
+
const arr = []
|
|
457
|
+
for (const key in obj) {
|
|
458
458
|
let value = obj[key]
|
|
459
459
|
if (Array.isArray(value)) {
|
|
460
460
|
value = `[${value.join(',')}]`
|
|
@@ -504,7 +504,7 @@ module.exports = {
|
|
|
504
504
|
},
|
|
505
505
|
event: {
|
|
506
506
|
parseEvent (attr) {
|
|
507
|
-
|
|
507
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
508
508
|
if (match) {
|
|
509
509
|
return {
|
|
510
510
|
prefix: match[1],
|
|
@@ -520,8 +520,8 @@ module.exports = {
|
|
|
520
520
|
defaultModelEvent: 'input',
|
|
521
521
|
defaultModelValuePath: 'value',
|
|
522
522
|
shallowStringify (obj) {
|
|
523
|
-
|
|
524
|
-
for (
|
|
523
|
+
const arr = []
|
|
524
|
+
for (const key in obj) {
|
|
525
525
|
let value = obj[key]
|
|
526
526
|
if (Array.isArray(value)) {
|
|
527
527
|
value = `[${value.join(',')}]`
|
|
@@ -50,7 +50,7 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
50
50
|
}
|
|
51
51
|
) {
|
|
52
52
|
const importedModule = moduleGraph.getModule(dep)
|
|
53
|
-
|
|
53
|
+
const requireExpr = runtimeTemplate.moduleExports({
|
|
54
54
|
module: importedModule,
|
|
55
55
|
chunkGraph,
|
|
56
56
|
request: dep.request,
|
|
@@ -73,13 +73,20 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
73
73
|
resource = addQuery(resource, { packageRoot }, true)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const key = resource
|
|
77
|
-
let addEntryPromise
|
|
76
|
+
const key = [resource, filename].join('|')
|
|
78
77
|
|
|
79
78
|
if (alreadyOutputted) {
|
|
80
|
-
addEntryPromise = mpx.addEntryPromiseMap.get(key)
|
|
79
|
+
const addEntryPromise = mpx.addEntryPromiseMap.get(key)
|
|
80
|
+
if (addEntryPromise) {
|
|
81
|
+
addEntryPromise.then(entryModule => {
|
|
82
|
+
// 构建entry依赖图,针对alreadyOutputted的entry也需要记录
|
|
83
|
+
originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
// alreadyOutputted时直接返回,避免存在模块循环引用时死循环
|
|
87
|
+
return callback(null, { resultPath })
|
|
81
88
|
} else {
|
|
82
|
-
addEntryPromise = new Promise((resolve, reject) => {
|
|
89
|
+
const addEntryPromise = new Promise((resolve, reject) => {
|
|
83
90
|
mpx.addEntry(resource, filename, (err, entryModule) => {
|
|
84
91
|
if (err) return reject(err)
|
|
85
92
|
if (entryType === 'export') {
|
|
@@ -88,15 +95,15 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
88
95
|
resolve(entryModule)
|
|
89
96
|
})
|
|
90
97
|
})
|
|
98
|
+
addEntryPromise
|
|
99
|
+
.then(entryModule => {
|
|
100
|
+
originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
101
|
+
callback(null, { resultPath })
|
|
102
|
+
})
|
|
103
|
+
.catch(err => callback(err))
|
|
104
|
+
|
|
91
105
|
mpx.addEntryPromiseMap.set(key, addEntryPromise)
|
|
92
106
|
}
|
|
93
|
-
|
|
94
|
-
addEntryPromise
|
|
95
|
-
.then(entryModule => {
|
|
96
|
-
if (entryModule) originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
97
|
-
callback(null, { resultPath })
|
|
98
|
-
})
|
|
99
|
-
.catch(err => callback(err))
|
|
100
107
|
}
|
|
101
108
|
], callback)
|
|
102
109
|
}
|
package/lib/extractor.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
22
22
|
|
|
23
23
|
if (needBabel) {
|
|
24
24
|
// 创建js request应用babel
|
|
25
|
-
|
|
25
|
+
const request = addQuery(this.request, {}, true, ['needBabel'])
|
|
26
26
|
const fakeRequest = addQuery(`${resourcePath}.js`, queryObj)
|
|
27
27
|
return `module.exports = require(${loaderUtils.stringifyRequest(this, `${fakeRequest}!=!${request}`)});\n`
|
|
28
28
|
}
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const loaderUtils = require('loader-utils')
|
|
2
2
|
const normalize = require('./utils/normalize')
|
|
3
3
|
const selectorPath = normalize.lib('selector')
|
|
4
|
+
const scriptSetupPath = normalize.lib('script-setup-compiler/index')
|
|
4
5
|
const addQuery = require('./utils/add-query')
|
|
5
6
|
const parseRequest = require('./utils/parse-request')
|
|
6
7
|
|
|
@@ -68,7 +69,8 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
68
69
|
return loaderUtils.stringifyRequest(loaderContext, addQuery(src, options, true))
|
|
69
70
|
} else {
|
|
70
71
|
const fakeRequest = getFakeRequest(type, part)
|
|
71
|
-
|
|
72
|
+
let request = `${selectorPath}?mode=${mode}&env=${env}!${addQuery(rawRequest, options, true)}`
|
|
73
|
+
if (part.setup && type === 'script') request = scriptSetupPath + '!' + request
|
|
72
74
|
return loaderUtils.stringifyRequest(loaderContext, `${fakeRequest}!=!${request}`)
|
|
73
75
|
}
|
|
74
76
|
}
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const FileSystemInfo = require('webpack/lib/FileSystemInfo')
|
|
|
17
17
|
const normalize = require('./utils/normalize')
|
|
18
18
|
const toPosix = require('./utils/to-posix')
|
|
19
19
|
const addQuery = require('./utils/add-query')
|
|
20
|
+
const hasOwn = require('./utils/has-own')
|
|
20
21
|
const { every } = require('./utils/set')
|
|
21
22
|
const DefinePlugin = require('webpack/lib/DefinePlugin')
|
|
22
23
|
const ExternalsPlugin = require('webpack/lib/ExternalsPlugin')
|
|
@@ -41,7 +42,7 @@ const PartialCompilePlugin = require('./partial-compile/index')
|
|
|
41
42
|
const fixRelative = require('./utils/fix-relative')
|
|
42
43
|
const parseRequest = require('./utils/parse-request')
|
|
43
44
|
const { matchCondition } = require('./utils/match-condition')
|
|
44
|
-
const
|
|
45
|
+
const processDefs = require('./utils/process-defs')
|
|
45
46
|
const config = require('./config')
|
|
46
47
|
const hash = require('hash-sum')
|
|
47
48
|
const wxssLoaderPath = normalize.lib('wxss/loader')
|
|
@@ -129,9 +130,9 @@ class MpxWebpackPlugin {
|
|
|
129
130
|
}
|
|
130
131
|
// 通过默认defs配置实现mode及srcMode的注入,简化内部处理逻辑
|
|
131
132
|
options.defs = Object.assign({}, options.defs, {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
__mpx_mode__: options.mode,
|
|
134
|
+
__mpx_src_mode__: options.srcMode,
|
|
135
|
+
__mpx_env__: options.env
|
|
135
136
|
})
|
|
136
137
|
// 批量指定源码mode
|
|
137
138
|
options.modeRules = options.modeRules || {}
|
|
@@ -318,8 +319,8 @@ class MpxWebpackPlugin {
|
|
|
318
319
|
const optimization = compiler.options.optimization
|
|
319
320
|
optimization.runtimeChunk = {
|
|
320
321
|
name: (entrypoint) => {
|
|
321
|
-
for (
|
|
322
|
-
if (mpx.independentSubpackagesMap
|
|
322
|
+
for (const packageName in mpx.independentSubpackagesMap) {
|
|
323
|
+
if (hasOwn(mpx.independentSubpackagesMap, packageName) && isChunkInPackage(entrypoint.name, packageName)) {
|
|
323
324
|
return `${packageName}/bundle`
|
|
324
325
|
}
|
|
325
326
|
}
|
|
@@ -361,7 +362,7 @@ class MpxWebpackPlugin {
|
|
|
361
362
|
const typeExtMap = config[this.options.mode].typeExtMap
|
|
362
363
|
|
|
363
364
|
const defsOpt = {
|
|
364
|
-
|
|
365
|
+
__mpx_wxs__: DefinePlugin.runtimeValue(({ module }) => {
|
|
365
366
|
return JSON.stringify(!!module.wxs)
|
|
366
367
|
})
|
|
367
368
|
}
|
|
@@ -564,7 +565,7 @@ class MpxWebpackPlugin {
|
|
|
564
565
|
webConfig: this.options.webConfig,
|
|
565
566
|
vueContentCache: new Map(),
|
|
566
567
|
tabBarMap: {},
|
|
567
|
-
defs:
|
|
568
|
+
defs: processDefs(this.options.defs),
|
|
568
569
|
i18n: this.options.i18n,
|
|
569
570
|
checkUsingComponents: this.options.checkUsingComponents,
|
|
570
571
|
forceDisableBuiltInLoader: this.options.forceDisableBuiltInLoader,
|
|
@@ -644,7 +645,7 @@ class MpxWebpackPlugin {
|
|
|
644
645
|
if (!currentResourceMap[resourcePath] || currentResourceMap[resourcePath] === true) {
|
|
645
646
|
if (!recordOnly) {
|
|
646
647
|
// 在非recordOnly的模式下,进行输出路径冲突检测,如果存在输出路径冲突,则对输出路径进行重命名
|
|
647
|
-
for (
|
|
648
|
+
for (const key in currentResourceMap) {
|
|
648
649
|
// todo 用outputPathMap来检测输出路径冲突
|
|
649
650
|
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
650
651
|
outputPath = mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })
|
|
@@ -860,7 +861,7 @@ class MpxWebpackPlugin {
|
|
|
860
861
|
if (splitChunksPlugin) {
|
|
861
862
|
let needInit = false
|
|
862
863
|
Object.keys(mpx.componentsMap).forEach((packageName) => {
|
|
863
|
-
if (!splitChunksOptions.cacheGroups
|
|
864
|
+
if (!hasOwn(splitChunksOptions.cacheGroups, packageName)) {
|
|
864
865
|
needInit = true
|
|
865
866
|
splitChunksOptions.cacheGroups[packageName] = getPackageCacheGroup(packageName)
|
|
866
867
|
}
|
|
@@ -1083,7 +1084,7 @@ class MpxWebpackPlugin {
|
|
|
1083
1084
|
current.addPresentationalDependency(dep)
|
|
1084
1085
|
|
|
1085
1086
|
let needInject = true
|
|
1086
|
-
for (
|
|
1087
|
+
for (const dep of module.dependencies) {
|
|
1087
1088
|
if (dep instanceof CommonJsVariableDependency && dep.name === name) {
|
|
1088
1089
|
needInject = false
|
|
1089
1090
|
break
|
|
@@ -1213,14 +1214,14 @@ class MpxWebpackPlugin {
|
|
|
1213
1214
|
return
|
|
1214
1215
|
}
|
|
1215
1216
|
|
|
1216
|
-
|
|
1217
|
+
const originalSource = compilation.assets[chunkFile]
|
|
1217
1218
|
const source = new ConcatSource()
|
|
1218
1219
|
source.add(`\nvar ${globalObject} = ${globalObject} || {};\n\n`)
|
|
1219
1220
|
|
|
1220
1221
|
relativeChunks.forEach((relativeChunk, index) => {
|
|
1221
1222
|
const relativeChunkFile = relativeChunk.files.values().next().value
|
|
1222
1223
|
if (!relativeChunkFile) return
|
|
1223
|
-
|
|
1224
|
+
const chunkPath = getTargetFile(chunkFile)
|
|
1224
1225
|
let relativePath = getTargetFile(relativeChunkFile)
|
|
1225
1226
|
relativePath = path.relative(path.dirname(chunkPath), relativePath)
|
|
1226
1227
|
relativePath = fixRelative(relativePath, mpx.mode)
|
|
@@ -1309,9 +1310,9 @@ try {
|
|
|
1309
1310
|
}
|
|
1310
1311
|
|
|
1311
1312
|
let runtimeChunk, entryChunk
|
|
1312
|
-
|
|
1313
|
+
const middleChunks = []
|
|
1313
1314
|
|
|
1314
|
-
|
|
1315
|
+
const chunksLength = chunkGroup.chunks.length
|
|
1315
1316
|
|
|
1316
1317
|
chunkGroup.chunks.forEach((chunk, index) => {
|
|
1317
1318
|
if (index === 0) {
|
|
@@ -1342,8 +1343,8 @@ try {
|
|
|
1342
1343
|
compiler.hooks.normalModuleFactory.tap('MpxWebpackPlugin', (normalModuleFactory) => {
|
|
1343
1344
|
// resolve前修改原始request
|
|
1344
1345
|
normalModuleFactory.hooks.beforeResolve.tap('MpxWebpackPlugin', (data) => {
|
|
1345
|
-
|
|
1346
|
-
|
|
1346
|
+
const request = data.request
|
|
1347
|
+
const { queryObj, resource } = parseRequest(request)
|
|
1347
1348
|
if (queryObj.resolve) {
|
|
1348
1349
|
// 此处的query用于将资源引用的当前包信息传递给resolveDependency
|
|
1349
1350
|
const resolveLoaderPath = normalize.lib('resolve-loader')
|
|
@@ -1365,7 +1366,7 @@ try {
|
|
|
1365
1366
|
const extract = queryObj.extract
|
|
1366
1367
|
switch (type) {
|
|
1367
1368
|
case 'styles':
|
|
1368
|
-
case 'template':
|
|
1369
|
+
case 'template': {
|
|
1369
1370
|
let insertBeforeIndex = -1
|
|
1370
1371
|
const info = typeLoaderProcessInfo[type]
|
|
1371
1372
|
loaders.forEach((loader, index) => {
|
|
@@ -1383,6 +1384,7 @@ try {
|
|
|
1383
1384
|
})
|
|
1384
1385
|
}
|
|
1385
1386
|
break
|
|
1387
|
+
}
|
|
1386
1388
|
case 'json':
|
|
1387
1389
|
if (queryObj.isTheme) {
|
|
1388
1390
|
loaders.unshift({
|
|
@@ -1402,6 +1404,7 @@ try {
|
|
|
1402
1404
|
loaders.unshift({
|
|
1403
1405
|
loader: wxsLoaderPath
|
|
1404
1406
|
})
|
|
1407
|
+
break
|
|
1405
1408
|
}
|
|
1406
1409
|
if (extract) {
|
|
1407
1410
|
loaders.unshift({
|
|
@@ -1420,11 +1423,11 @@ try {
|
|
|
1420
1423
|
let mpxStyleLoaderIndex = -1
|
|
1421
1424
|
loaders.forEach((loader, index) => {
|
|
1422
1425
|
const currentLoader = toPosix(loader.loader)
|
|
1423
|
-
if (currentLoader.includes('css-loader')
|
|
1426
|
+
if (currentLoader.includes('css-loader')) {
|
|
1424
1427
|
cssLoaderIndex = index
|
|
1425
|
-
} else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')
|
|
1428
|
+
} else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')) {
|
|
1426
1429
|
vueStyleLoaderIndex = index
|
|
1427
|
-
} else if (currentLoader.includes(styleCompilerPath)
|
|
1430
|
+
} else if (currentLoader.includes(styleCompilerPath)) {
|
|
1428
1431
|
mpxStyleLoaderIndex = index
|
|
1429
1432
|
}
|
|
1430
1433
|
})
|
|
@@ -72,7 +72,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
72
72
|
name = info.descriptionFileData.name.replace(/@/g, '')
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
const relative = path.relative(root, resourceName)
|
|
76
76
|
outputPath = path.join('components', name + pathHash(root), relative)
|
|
77
77
|
} else {
|
|
78
78
|
outputPath = getOutputPath(resourcePath, 'component')
|
|
@@ -97,7 +97,7 @@ module.exports = function (content) {
|
|
|
97
97
|
fs.readFile(file, (err, content) => {
|
|
98
98
|
if (err) return callback(err)
|
|
99
99
|
if (!this._compilation) return callback()
|
|
100
|
-
|
|
100
|
+
const targetPath = path.relative(context, file)
|
|
101
101
|
this._compilation.assets[targetPath] = {
|
|
102
102
|
size: function size () {
|
|
103
103
|
return stats.size
|
|
@@ -119,7 +119,7 @@ module.exports = function (content) {
|
|
|
119
119
|
if (err) return nativeCallback(err)
|
|
120
120
|
let output = `var json = ${JSON.stringify(json, null, 2)};\n`
|
|
121
121
|
if (processOutput) output = processOutput(output)
|
|
122
|
-
output +=
|
|
122
|
+
output += 'module.exports = JSON.stringify(json, null, 2);\n'
|
|
123
123
|
nativeCallback(null, output)
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -292,10 +292,10 @@ module.exports = function (content) {
|
|
|
292
292
|
const context = path.dirname(result)
|
|
293
293
|
|
|
294
294
|
if (content.pages) {
|
|
295
|
-
|
|
295
|
+
const tarRoot = queryObj.root
|
|
296
296
|
if (tarRoot) {
|
|
297
297
|
delete queryObj.root
|
|
298
|
-
|
|
298
|
+
const subPackage = {
|
|
299
299
|
tarRoot,
|
|
300
300
|
pages: content.pages,
|
|
301
301
|
...queryObj
|
|
@@ -335,14 +335,14 @@ module.exports = function (content) {
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
const getOtherConfig = (config) => {
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
const result = {}
|
|
339
|
+
const blackListMap = {
|
|
340
340
|
tarRoot: true,
|
|
341
341
|
srcRoot: true,
|
|
342
342
|
root: true,
|
|
343
343
|
pages: true
|
|
344
344
|
}
|
|
345
|
-
for (
|
|
345
|
+
for (const key in config) {
|
|
346
346
|
if (!blackListMap[key]) {
|
|
347
347
|
result[key] = config[key]
|
|
348
348
|
}
|
|
@@ -382,8 +382,8 @@ module.exports = function (content) {
|
|
|
382
382
|
emitError(`Current subpackage root [${subPackage.root}] is not allow starts with '.'`)
|
|
383
383
|
return callback()
|
|
384
384
|
}
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
const tarRoot = subPackage.tarRoot || subPackage.root || ''
|
|
386
|
+
const srcRoot = subPackage.srcRoot || subPackage.root || ''
|
|
387
387
|
if (!tarRoot || subPackagesCfg[tarRoot]) return callback()
|
|
388
388
|
|
|
389
389
|
context = path.join(context, srcRoot)
|
|
@@ -423,10 +423,10 @@ module.exports = function (content) {
|
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
const processTabBar = (output) => {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
const tabBarCfg = config[mode].tabBar
|
|
427
|
+
const itemKey = tabBarCfg.itemKey
|
|
428
|
+
const iconKey = tabBarCfg.iconKey
|
|
429
|
+
const activeIconKey = tabBarCfg.activeIconKey
|
|
430
430
|
|
|
431
431
|
if (json.tabBar && json.tabBar[itemKey]) {
|
|
432
432
|
json.tabBar[itemKey].forEach((item, index) => {
|
|
@@ -442,9 +442,9 @@ module.exports = function (content) {
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
const processOptionMenu = (output) => {
|
|
445
|
-
|
|
445
|
+
const optionMenuCfg = config[mode].optionMenu
|
|
446
446
|
if (optionMenuCfg && json.optionMenu) {
|
|
447
|
-
|
|
447
|
+
const iconKey = optionMenuCfg.iconKey
|
|
448
448
|
if (json.optionMenu[iconKey] && isUrlRequest(json.optionMenu[iconKey])) {
|
|
449
449
|
output += `json.optionMenu.${iconKey} = require("${addQuery(urlToRequest(json.optionMenu[iconKey]), { useLocal: true })}");\n`
|
|
450
450
|
}
|
|
@@ -465,7 +465,7 @@ module.exports = function (content) {
|
|
|
465
465
|
|
|
466
466
|
const processWorkers = (workers, context, callback) => {
|
|
467
467
|
if (workers) {
|
|
468
|
-
|
|
468
|
+
const workersPath = path.join(context, workers)
|
|
469
469
|
this.addContextDependency(workersPath)
|
|
470
470
|
copydir(workersPath, context, callback)
|
|
471
471
|
} else {
|
|
@@ -571,7 +571,7 @@ module.exports = function (content) {
|
|
|
571
571
|
delete json.subpackages
|
|
572
572
|
delete json.subPackages
|
|
573
573
|
json.pages = localPages
|
|
574
|
-
for (
|
|
574
|
+
for (const root in subPackagesCfg) {
|
|
575
575
|
const subPackageCfg = subPackagesCfg[root]
|
|
576
576
|
// 分包不存在 pages,输出 subPackages 字段会报错
|
|
577
577
|
if (subPackageCfg.pages.length) {
|
|
@@ -57,7 +57,7 @@ module.exports = function (source) {
|
|
|
57
57
|
if (err) return nativeCallback(err)
|
|
58
58
|
let output = `var pluginEntry = ${JSON.stringify(pluginEntry, null, 2)};\n`
|
|
59
59
|
if (processOutput) output = processOutput(output)
|
|
60
|
-
output +=
|
|
60
|
+
output += 'module.exports = JSON.stringify(pluginEntry, null, 2);\n'
|
|
61
61
|
nativeCallback(null, output)
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -105,9 +105,10 @@ module.exports = function (source) {
|
|
|
105
105
|
const item = publicPages[key]
|
|
106
106
|
reversedMap[item] = key
|
|
107
107
|
})
|
|
108
|
-
pages = pages.reduce((
|
|
108
|
+
pages = pages.reduce((target, page, index) => {
|
|
109
109
|
const key = reversedMap[page] || `__private_page_${index}__`
|
|
110
110
|
target[key] = page
|
|
111
|
+
return target
|
|
111
112
|
}, {})
|
|
112
113
|
}
|
|
113
114
|
|
package/lib/loader.js
CHANGED
|
@@ -105,7 +105,7 @@ module.exports = function (content) {
|
|
|
105
105
|
|
|
106
106
|
if (parts.json && parts.json.content) {
|
|
107
107
|
try {
|
|
108
|
-
|
|
108
|
+
const ret = JSON5.parse(parts.json.content)
|
|
109
109
|
if (ret.usingComponents) {
|
|
110
110
|
fixUsingComponent(ret.usingComponents, mode)
|
|
111
111
|
usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
|
|
@@ -117,7 +117,6 @@ module.exports = function (content) {
|
|
|
117
117
|
return callback(e)
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
|
|
121
120
|
// 处理mode为web时输出vue格式文件
|
|
122
121
|
if (mode === 'web') {
|
|
123
122
|
if (ctorType === 'app' && !queryObj.isApp) {
|
|
@@ -330,7 +329,8 @@ module.exports = function (content) {
|
|
|
330
329
|
...script.src
|
|
331
330
|
? { ...queryObj, resourcePath }
|
|
332
331
|
: null,
|
|
333
|
-
ctorType
|
|
332
|
+
ctorType,
|
|
333
|
+
lang: script.lang || 'js'
|
|
334
334
|
}
|
|
335
335
|
output += getRequire('script', script, extraOptions) + '\n'
|
|
336
336
|
}
|
package/lib/native-loader.js
CHANGED
|
@@ -197,7 +197,7 @@ module.exports = function (content) {
|
|
|
197
197
|
output += `global.currentSrcMode = ${JSON.stringify(srcMode)}\n`
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
for (
|
|
200
|
+
for (const type in typeResourceMap) {
|
|
201
201
|
output += `/* ${type} */\n${getRequireByType(type)}\n\n`
|
|
202
202
|
}
|
|
203
203
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const hasOwn = require('../../utils/has-own')
|
|
2
|
+
|
|
1
3
|
module.exports = function normalizeTest (test) {
|
|
2
4
|
if (test) {
|
|
3
5
|
return (input, meta) => {
|
|
@@ -5,7 +7,7 @@ module.exports = function normalizeTest (test) {
|
|
|
5
7
|
meta.paths = []
|
|
6
8
|
let result = false
|
|
7
9
|
for (let i = 0; i < pathArr.length; i++) {
|
|
8
|
-
if (input
|
|
10
|
+
if (hasOwn(input, pathArr[i])) {
|
|
9
11
|
meta.paths.push(pathArr[i])
|
|
10
12
|
result = true
|
|
11
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const type = require('../utils/type')
|
|
2
2
|
|
|
3
3
|
function defaultNormalizeTest (rawTest, context) {
|
|
4
|
-
|
|
4
|
+
const testType = type(rawTest)
|
|
5
5
|
switch (testType) {
|
|
6
6
|
case 'Function':
|
|
7
7
|
return rawTest.bind(context)
|
|
@@ -27,7 +27,7 @@ module.exports = function runRules (rules = [], input, options = {}) {
|
|
|
27
27
|
mode
|
|
28
28
|
})
|
|
29
29
|
if (tester(testInput, meta) && processor) {
|
|
30
|
-
|
|
30
|
+
const result = processor.call(rule, input, data, meta)
|
|
31
31
|
meta.processed = true
|
|
32
32
|
if (result !== undefined) {
|
|
33
33
|
input = result
|
|
@@ -58,9 +58,9 @@ module.exports = function ({ print }) {
|
|
|
58
58
|
prop.name = propsMap[prop.name]
|
|
59
59
|
if (prop.name === 'framesize') {
|
|
60
60
|
const valueMap = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
small: 'low',
|
|
62
|
+
medium: 'medium',
|
|
63
|
+
large: 'high'
|
|
64
64
|
}
|
|
65
65
|
prop.value = valueMap[prop.value]
|
|
66
66
|
}
|
|
@@ -35,11 +35,11 @@ module.exports = function ({ print }) {
|
|
|
35
35
|
test: /^(touchstart|touchmove|touchend|touchcancel|longtap)$/,
|
|
36
36
|
ali (eventName) {
|
|
37
37
|
const eventMap = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
touchstart: 'touchStart',
|
|
39
|
+
touchmove: 'touchMove',
|
|
40
|
+
touchend: 'touchEnd',
|
|
41
|
+
touchcancel: 'touchCancel',
|
|
42
|
+
longtap: 'longTap'
|
|
43
43
|
}
|
|
44
44
|
return eventMap[eventName]
|
|
45
45
|
}
|