@mpxjs/webpack-plugin 2.9.0-beta.0 → 2.9.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/dependencies/DynamicEntryDependency.js +10 -16
- package/lib/dependencies/ResolveDependency.js +11 -9
- package/lib/index.js +73 -30
- package/lib/json-compiler/default-page.mpx +3 -0
- package/lib/json-compiler/helper.js +7 -4
- package/lib/json-compiler/index.js +41 -19
- package/lib/loader.js +2 -9
- package/lib/native-loader.js +3 -8
- package/lib/parser.js +0 -1
- package/lib/platform/json/wx/index.js +21 -0
- package/lib/platform/template/wx/component-config/component.js +1 -2
- 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 +12 -14
- package/lib/runtime/components/web/getInnerListeners.js +16 -2
- package/lib/runtime/components/web/mpx-checkbox-group.vue +1 -1
- package/lib/runtime/components/web/mpx-form.vue +2 -2
- package/lib/runtime/components/web/mpx-image.vue +11 -15
- package/lib/runtime/components/web/mpx-movable-view.vue +3 -3
- package/lib/runtime/components/web/mpx-picker-view.vue +5 -5
- package/lib/runtime/components/web/mpx-picker.vue +3 -3
- package/lib/runtime/components/web/mpx-progress.vue +3 -1
- package/lib/runtime/components/web/mpx-radio-group.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +9 -9
- package/lib/runtime/components/web/mpx-slider.vue +4 -4
- package/lib/runtime/components/web/mpx-swiper.vue +3 -3
- package/lib/runtime/components/web/mpx-switch.vue +1 -1
- package/lib/runtime/components/web/mpx-video.vue +14 -28
- package/lib/runtime/components/web/mpx-web-view.vue +4 -4
- package/lib/runtime/stringify.wxs +44 -8
- package/lib/style-compiler/index.js +3 -1
- package/lib/template-compiler/compiler.js +73 -50
- package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -18
- package/lib/wxss/runtime/api.js +18 -19
- package/lib/wxss/runtime/noSourceMaps.js +3 -1
- package/lib/wxss/runtime/sourceMaps.js +8 -7
- package/package.json +3 -3
- package/lib/partial-compile/index.js +0 -35
|
@@ -28,23 +28,10 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
28
28
|
return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
collectDynamicRequest (mpx) {
|
|
32
|
-
if (!this.packageRoot) return
|
|
33
|
-
const curValue = mpx.dynamicEntryInfo[this.packageRoot] = mpx.dynamicEntryInfo[this.packageRoot] || {
|
|
34
|
-
hasPage: false,
|
|
35
|
-
entries: []
|
|
36
|
-
}
|
|
37
|
-
if (this.entryType === 'page') {
|
|
38
|
-
curValue.hasPage = true
|
|
39
|
-
} else {
|
|
40
|
-
curValue.entries.push(this.request)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
31
|
addEntry (compilation, callback) {
|
|
45
32
|
const mpx = compilation.__mpx__
|
|
46
33
|
let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver } = this
|
|
47
|
-
|
|
34
|
+
|
|
48
35
|
async.waterfall([
|
|
49
36
|
(callback) => {
|
|
50
37
|
if (context && resolver) {
|
|
@@ -56,12 +43,13 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
56
43
|
}
|
|
57
44
|
},
|
|
58
45
|
(resource, callback) => {
|
|
46
|
+
const { resourcePath } = parseRequest(resource)
|
|
47
|
+
|
|
59
48
|
if (!outputPath) {
|
|
60
|
-
const { resourcePath } = parseRequest(resource)
|
|
61
49
|
outputPath = mpx.getOutputPath(resourcePath, entryType)
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
|
|
52
|
+
const { packageName, packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
|
|
65
53
|
resource,
|
|
66
54
|
outputPath,
|
|
67
55
|
resourceType: entryType,
|
|
@@ -116,6 +104,12 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
116
104
|
.catch(err => callback(err))
|
|
117
105
|
|
|
118
106
|
mpx.addEntryPromiseMap.set(key, addEntryPromise)
|
|
107
|
+
mpx.collectDynamicEntryInfo({
|
|
108
|
+
resource,
|
|
109
|
+
packageName,
|
|
110
|
+
filename,
|
|
111
|
+
entryType
|
|
112
|
+
})
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
], callback)
|
|
@@ -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')
|
|
@@ -112,7 +112,6 @@ class MpxWebpackPlugin {
|
|
|
112
112
|
constructor (options = {}) {
|
|
113
113
|
options.mode = options.mode || 'wx'
|
|
114
114
|
options.env = options.env || ''
|
|
115
|
-
|
|
116
115
|
options.srcMode = options.srcMode || options.mode
|
|
117
116
|
if (options.mode !== options.srcMode && options.srcMode !== 'wx') {
|
|
118
117
|
errors.push('MpxWebpackPlugin supports srcMode to be "wx" only temporarily!')
|
|
@@ -381,7 +380,33 @@ class MpxWebpackPlugin {
|
|
|
381
380
|
let mpx
|
|
382
381
|
|
|
383
382
|
if (this.options.partialCompile) {
|
|
384
|
-
|
|
383
|
+
function isResolvingPage (obj) {
|
|
384
|
+
// valid query should start with '?'
|
|
385
|
+
const query = parseQuery(obj.query || '?')
|
|
386
|
+
return query.isPage && !query.type
|
|
387
|
+
}
|
|
388
|
+
// new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
|
|
389
|
+
compiler.resolverFactory.hooks.resolver.intercept({
|
|
390
|
+
factory: (type, hook) => {
|
|
391
|
+
hook.tap('MpxPartialCompilePlugin', (resolver) => {
|
|
392
|
+
resolver.hooks.result.tapAsync({
|
|
393
|
+
name: 'MpxPartialCompilePlugin',
|
|
394
|
+
stage: -100
|
|
395
|
+
}, (obj, resolverContext, callback) => {
|
|
396
|
+
if (obj.path.startsWith(require.resolve('./json-compiler/default-page.mpx'))) {
|
|
397
|
+
return callback(null, obj)
|
|
398
|
+
}
|
|
399
|
+
if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
|
|
400
|
+
const infix = obj.query ? '&' : '?'
|
|
401
|
+
obj.query += `${infix}resourcePath=${obj.path}`
|
|
402
|
+
obj.path = require.resolve('./json-compiler/default-page.mpx')
|
|
403
|
+
}
|
|
404
|
+
callback(null, obj)
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
return hook
|
|
408
|
+
}
|
|
409
|
+
})
|
|
385
410
|
}
|
|
386
411
|
|
|
387
412
|
const getPackageCacheGroup = packageName => {
|
|
@@ -455,17 +480,17 @@ class MpxWebpackPlugin {
|
|
|
455
480
|
}, (compilation, callback) => {
|
|
456
481
|
processSubpackagesEntriesMap(compilation, (err) => {
|
|
457
482
|
if (err) return callback(err)
|
|
458
|
-
const
|
|
459
|
-
for (const
|
|
460
|
-
const entryMap = mpx.dynamicEntryInfo[
|
|
461
|
-
if (!entryMap.hasPage) {
|
|
483
|
+
const checkDynamicEntryInfo = () => {
|
|
484
|
+
for (const packageName in mpx.dynamicEntryInfo) {
|
|
485
|
+
const entryMap = mpx.dynamicEntryInfo[packageName]
|
|
486
|
+
if (packageName !== 'main' && !entryMap.hasPage) {
|
|
462
487
|
// 引用未注册分包的所有资源
|
|
463
|
-
const
|
|
464
|
-
compilation.errors.push(new Error(`资源${
|
|
488
|
+
const resources = entryMap.entries.map(info => info.resource).join(',')
|
|
489
|
+
compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`))
|
|
465
490
|
}
|
|
466
491
|
}
|
|
467
492
|
}
|
|
468
|
-
|
|
493
|
+
checkDynamicEntryInfo()
|
|
469
494
|
callback()
|
|
470
495
|
})
|
|
471
496
|
})
|
|
@@ -522,8 +547,8 @@ class MpxWebpackPlugin {
|
|
|
522
547
|
})
|
|
523
548
|
|
|
524
549
|
compiler.hooks.thisCompilation.tap('MpxWebpackPlugin', (compilation, { normalModuleFactory }) => {
|
|
525
|
-
compilation.warnings
|
|
526
|
-
compilation.errors
|
|
550
|
+
compilation.warnings.push(...warnings)
|
|
551
|
+
compilation.errors.push(...errors)
|
|
527
552
|
const moduleGraph = compilation.moduleGraph
|
|
528
553
|
|
|
529
554
|
if (!compilation.__mpx__) {
|
|
@@ -552,7 +577,7 @@ class MpxWebpackPlugin {
|
|
|
552
577
|
subpackagesEntriesMap: {},
|
|
553
578
|
replacePathMap: {},
|
|
554
579
|
exportModules: new Set(),
|
|
555
|
-
//
|
|
580
|
+
// 记录动态添加入口的分包信息
|
|
556
581
|
dynamicEntryInfo: {},
|
|
557
582
|
// 记录entryModule与entryNode的对应关系,用于体积分析
|
|
558
583
|
entryNodeModulesMap: new Map(),
|
|
@@ -594,14 +619,27 @@ class MpxWebpackPlugin {
|
|
|
594
619
|
useRelativePath: this.options.useRelativePath,
|
|
595
620
|
removedChunks: [],
|
|
596
621
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
597
|
-
|
|
622
|
+
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
|
|
623
|
+
partialCompile: this.options.partialCompile,
|
|
624
|
+
collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
|
|
625
|
+
const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
|
|
626
|
+
hasPage: false,
|
|
627
|
+
entries: []
|
|
628
|
+
}
|
|
629
|
+
if (entryType === 'page') curInfo.hasPage = true
|
|
630
|
+
curInfo.entries.push({
|
|
631
|
+
entryType,
|
|
632
|
+
resource,
|
|
633
|
+
filename
|
|
634
|
+
})
|
|
635
|
+
},
|
|
598
636
|
pathHash: (resourcePath) => {
|
|
599
637
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
600
638
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
601
639
|
}
|
|
602
640
|
return hash(resourcePath)
|
|
603
641
|
},
|
|
604
|
-
addEntry (request, name, callback) {
|
|
642
|
+
addEntry: (request, name, callback) => {
|
|
605
643
|
const dep = EntryPlugin.createDependency(request, { name })
|
|
606
644
|
compilation.addEntry(compiler.context, dep, { name }, callback)
|
|
607
645
|
return dep
|
|
@@ -761,10 +799,14 @@ class MpxWebpackPlugin {
|
|
|
761
799
|
const rawProcessModuleDependencies = compilation.processModuleDependencies
|
|
762
800
|
compilation.processModuleDependencies = (module, callback) => {
|
|
763
801
|
const presentationalDependencies = module.presentationalDependencies || []
|
|
802
|
+
const errors = []
|
|
764
803
|
async.forEach(presentationalDependencies.filter((dep) => dep.mpxAction), (dep, callback) => {
|
|
765
|
-
dep.mpxAction(module, compilation,
|
|
766
|
-
|
|
767
|
-
|
|
804
|
+
dep.mpxAction(module, compilation, (err) => {
|
|
805
|
+
if (err) errors.push(err)
|
|
806
|
+
callback()
|
|
807
|
+
})
|
|
808
|
+
}, () => {
|
|
809
|
+
compilation.errors.push(...errors)
|
|
768
810
|
rawProcessModuleDependencies.call(compilation, module, callback)
|
|
769
811
|
})
|
|
770
812
|
}
|
|
@@ -850,16 +892,17 @@ class MpxWebpackPlugin {
|
|
|
850
892
|
}
|
|
851
893
|
|
|
852
894
|
// hack process https://github.com/webpack/webpack/issues/16045
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
895
|
+
// no need anymore
|
|
896
|
+
// const _handleModuleBuildAndDependenciesRaw = compilation._handleModuleBuildAndDependencies
|
|
897
|
+
//
|
|
898
|
+
// compilation._handleModuleBuildAndDependencies = (originModule, module, recursive, callback) => {
|
|
899
|
+
// const rawCallback = callback
|
|
900
|
+
// callback = (err) => {
|
|
901
|
+
// if (err) return rawCallback(err)
|
|
902
|
+
// return rawCallback(null, module)
|
|
903
|
+
// }
|
|
904
|
+
// return _handleModuleBuildAndDependenciesRaw.call(compilation, originModule, module, recursive, callback)
|
|
905
|
+
// }
|
|
863
906
|
|
|
864
907
|
const rawEmitAsset = compilation.emitAsset
|
|
865
908
|
|
|
@@ -1003,8 +1046,8 @@ class MpxWebpackPlugin {
|
|
|
1003
1046
|
if (queryObj.root) {
|
|
1004
1047
|
// 删除root query
|
|
1005
1048
|
request = addQuery(request, {}, false, ['root'])
|
|
1006
|
-
// 目前仅wx支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
|
|
1007
|
-
if (mpx.
|
|
1049
|
+
// 目前仅wx和ali支持require.async,ali需要开启enableAliRequireAsync,其余平台使用CommonJsAsyncDependency进行模拟抹平
|
|
1050
|
+
if (mpx.enableRequireAsync) {
|
|
1008
1051
|
const dep = new DynamicEntryDependency(request, 'export', '', queryObj.root, '', context, range, {
|
|
1009
1052
|
isRequireAsync: true,
|
|
1010
1053
|
retryRequireAsync: !!this.options.retryRequireAsync
|
|
@@ -16,7 +16,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
16
16
|
const pathHash = mpx.pathHash
|
|
17
17
|
const getOutputPath = mpx.getOutputPath
|
|
18
18
|
const mode = mpx.mode
|
|
19
|
-
const
|
|
19
|
+
const enableRequireAsync = mpx.enableRequireAsync
|
|
20
20
|
|
|
21
21
|
const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
|
|
22
22
|
const urlToRequest = r => loaderUtils.urlToRequest(r)
|
|
@@ -54,7 +54,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
54
54
|
// 删除root query
|
|
55
55
|
resource = addQuery(resource, {}, false, ['root'])
|
|
56
56
|
// 目前只有微信支持分包异步化
|
|
57
|
-
if (
|
|
57
|
+
if (enableRequireAsync) tarRoot = queryObj.root
|
|
58
58
|
}
|
|
59
59
|
const parsed = path.parse(resourcePath)
|
|
60
60
|
const ext = parsed.ext
|
|
@@ -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
|
}
|
|
@@ -143,15 +143,17 @@ module.exports = function (content) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// 校验异步组件占位符 componentPlaceholder 不为空
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
146
|
+
if (mpx.enableRequireAsync) {
|
|
147
|
+
const { usingComponents, componentPlaceholder = {} } = json
|
|
148
|
+
if (usingComponents) {
|
|
149
|
+
for (const compName in usingComponents) {
|
|
150
|
+
const compPath = usingComponents[compName]
|
|
151
|
+
if (!/\?root=/g.test(compPath)) continue
|
|
152
|
+
const compPlaceholder = componentPlaceholder[compName]
|
|
153
|
+
if (!compPlaceholder) {
|
|
154
|
+
const errMsg = `componentPlaceholder of "${compName}" doesn't exist! \n\r`
|
|
155
|
+
emitError(errMsg)
|
|
156
|
+
}
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
}
|
|
@@ -175,14 +177,14 @@ module.exports = function (content) {
|
|
|
175
177
|
type: 'json',
|
|
176
178
|
waterfall: true,
|
|
177
179
|
warn: emitWarning,
|
|
178
|
-
error: emitError
|
|
180
|
+
error: emitError,
|
|
181
|
+
data: {
|
|
182
|
+
// polyfill global usingComponents & record globalComponents
|
|
183
|
+
globalComponents: mpx.usingComponents
|
|
184
|
+
}
|
|
179
185
|
}
|
|
180
186
|
if (!isApp) {
|
|
181
187
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
182
|
-
// polyfill global usingComponents
|
|
183
|
-
rulesRunnerOptions.data = {
|
|
184
|
-
globalComponents: mpx.usingComponents
|
|
185
|
-
}
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
@@ -191,9 +193,12 @@ module.exports = function (content) {
|
|
|
191
193
|
rulesRunner(json)
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
if (isApp
|
|
196
|
+
if (isApp) {
|
|
197
|
+
Object.assign(mpx.usingComponents, json.usingComponents)
|
|
195
198
|
// 在 rulesRunner 运行后保存全局注册组件
|
|
196
|
-
|
|
199
|
+
// todo 其余地方在使用mpx.usingComponents时存在缓存问题,要规避该问题需要在所有使用mpx.usingComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
|
|
200
|
+
// todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
|
|
201
|
+
this._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, this.context))
|
|
197
202
|
}
|
|
198
203
|
|
|
199
204
|
const processComponents = (components, context, callback) => {
|
|
@@ -219,14 +224,20 @@ module.exports = function (content) {
|
|
|
219
224
|
const localPages = []
|
|
220
225
|
const subPackagesCfg = {}
|
|
221
226
|
const pageKeySet = new Set()
|
|
222
|
-
|
|
227
|
+
const defaultPagePath = require.resolve('./default-page.mpx')
|
|
223
228
|
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
224
229
|
if (pages) {
|
|
230
|
+
const pagesCache = []
|
|
225
231
|
async.each(pages, (page, callback) => {
|
|
226
|
-
processPage(page, context, tarRoot, (err, entry, { isFirst, key } = {}) => {
|
|
232
|
+
processPage(page, context, tarRoot, (err, entry, { isFirst, key, resource } = {}) => {
|
|
227
233
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
228
234
|
if (pageKeySet.has(key)) return callback()
|
|
235
|
+
if (resource.startsWith(defaultPagePath)) {
|
|
236
|
+
pagesCache.push(entry)
|
|
237
|
+
return callback()
|
|
238
|
+
}
|
|
229
239
|
pageKeySet.add(key)
|
|
240
|
+
|
|
230
241
|
if (tarRoot && subPackagesCfg) {
|
|
231
242
|
subPackagesCfg[tarRoot].pages.push(entry)
|
|
232
243
|
} else {
|
|
@@ -239,7 +250,18 @@ module.exports = function (content) {
|
|
|
239
250
|
}
|
|
240
251
|
callback()
|
|
241
252
|
})
|
|
242
|
-
},
|
|
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
|
+
})
|
|
243
265
|
} else {
|
|
244
266
|
callback()
|
|
245
267
|
}
|
package/lib/loader.js
CHANGED
|
@@ -119,7 +119,6 @@ module.exports = function (content) {
|
|
|
119
119
|
|
|
120
120
|
let usingComponents = [].concat(Object.keys(mpx.usingComponents))
|
|
121
121
|
let componentPlaceholder = []
|
|
122
|
-
|
|
123
122
|
let componentGenerics = {}
|
|
124
123
|
|
|
125
124
|
if (parts.json && parts.json.content) {
|
|
@@ -133,18 +132,12 @@ module.exports = function (content) {
|
|
|
133
132
|
}
|
|
134
133
|
if (!isApp) {
|
|
135
134
|
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
136
|
-
// polyfill global usingComponents
|
|
137
|
-
// 预读json时无需注入polyfill全局组件
|
|
138
|
-
// rulesRunnerOptions.data = {
|
|
139
|
-
// globalComponents: mpx.usingComponents
|
|
140
|
-
// }
|
|
141
135
|
}
|
|
142
|
-
|
|
136
|
+
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
143
137
|
try {
|
|
144
138
|
const ret = JSON5.parse(parts.json.content)
|
|
139
|
+
if (rulesRunner) rulesRunner(ret)
|
|
145
140
|
if (ret.usingComponents) {
|
|
146
|
-
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
147
|
-
if (rulesRunner) rulesRunner(ret)
|
|
148
141
|
usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
|
|
149
142
|
}
|
|
150
143
|
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 {
|
package/lib/parser.js
CHANGED
|
@@ -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,5 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const parseMustache = templateCompiler.parseMustache
|
|
1
|
+
const { parseMustache } = require('../../../../template-compiler/compiler')
|
|
3
2
|
const normalize = require('../../../../utils/normalize')
|
|
4
3
|
const TAG_NAME = 'component'
|
|
5
4
|
|
|
@@ -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
|
}
|