@mpxjs/webpack-plugin 2.9.66 → 2.9.69
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/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +29 -8
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +15 -10
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +20 -7
- package/lib/runtime/components/react/context.ts +2 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +46 -27
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
- package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +66 -6
- package/lib/runtime/components/react/getInnerListeners.ts +3 -16
- package/lib/runtime/components/react/mpx-button.tsx +42 -9
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
- package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +58 -28
- package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +2 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +94 -8
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +47 -16
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +5 -4
|
@@ -116,6 +116,7 @@ let i18nInjectableComputed = []
|
|
|
116
116
|
let hasOptionalChaining = false
|
|
117
117
|
let processingTemplate = false
|
|
118
118
|
const rulesResultMap = new Map()
|
|
119
|
+
let usingComponents = []
|
|
119
120
|
|
|
120
121
|
function updateForScopesMap () {
|
|
121
122
|
forScopesMap = {}
|
|
@@ -633,6 +634,9 @@ function parse (template, options) {
|
|
|
633
634
|
processingTemplate = false
|
|
634
635
|
rulesResultMap.clear()
|
|
635
636
|
|
|
637
|
+
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
638
|
+
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
639
|
+
|
|
636
640
|
const _warn = content => {
|
|
637
641
|
const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, {
|
|
638
642
|
warnArray: [],
|
|
@@ -654,7 +658,7 @@ function parse (template, options) {
|
|
|
654
658
|
type: 'template',
|
|
655
659
|
testKey: 'tag',
|
|
656
660
|
data: {
|
|
657
|
-
usingComponents
|
|
661
|
+
usingComponents
|
|
658
662
|
},
|
|
659
663
|
warn: _warn,
|
|
660
664
|
error: _error
|
|
@@ -804,7 +808,7 @@ function parse (template, options) {
|
|
|
804
808
|
|
|
805
809
|
if (!tagNames.has('component') && options.checkUsingComponents) {
|
|
806
810
|
const arr = []
|
|
807
|
-
|
|
811
|
+
usingComponents.forEach((item) => {
|
|
808
812
|
if (!tagNames.has(item) && !options.globalComponents.includes(item) && !options.componentPlaceholder.includes(item)) {
|
|
809
813
|
arr.push(item)
|
|
810
814
|
}
|
|
@@ -980,7 +984,7 @@ function processComponentIs (el, options) {
|
|
|
980
984
|
|
|
981
985
|
const range = getAndRemoveAttr(el, 'range').val
|
|
982
986
|
const isInRange = makeMap(range || '')
|
|
983
|
-
el.components = (
|
|
987
|
+
el.components = (usingComponents).filter(i => {
|
|
984
988
|
if (!range) return true
|
|
985
989
|
return isInRange(i)
|
|
986
990
|
})
|
|
@@ -1370,7 +1374,8 @@ function processEvent (el, options) {
|
|
|
1370
1374
|
function processSlotReact (el, meta) {
|
|
1371
1375
|
if (el.tag === 'slot') {
|
|
1372
1376
|
el.slot = {
|
|
1373
|
-
name: getAndRemoveAttr(el, 'name').val
|
|
1377
|
+
name: getAndRemoveAttr(el, 'name').val,
|
|
1378
|
+
slot: getAndRemoveAttr(el, 'slot').val
|
|
1374
1379
|
}
|
|
1375
1380
|
meta.options = meta.options || {}
|
|
1376
1381
|
meta.options.disableMemo = true
|
|
@@ -1763,6 +1768,15 @@ function processRefReact (el, meta) {
|
|
|
1763
1768
|
value: `{{ this.__getRefVal('${type}', [${selectorsConf}]) }}`
|
|
1764
1769
|
}])
|
|
1765
1770
|
}
|
|
1771
|
+
|
|
1772
|
+
if (el.tag === 'mpx-scroll-view' && el.attrsMap['scroll-into-view']) {
|
|
1773
|
+
addAttrs(el, [
|
|
1774
|
+
{
|
|
1775
|
+
name: '__selectRef',
|
|
1776
|
+
value: '{{ this.__selectRef.bind(this) }}'
|
|
1777
|
+
}
|
|
1778
|
+
])
|
|
1779
|
+
}
|
|
1766
1780
|
}
|
|
1767
1781
|
|
|
1768
1782
|
function processRef (el, options, meta) {
|
|
@@ -2137,7 +2151,7 @@ function processStyle (el, meta) {
|
|
|
2137
2151
|
}
|
|
2138
2152
|
|
|
2139
2153
|
function isRealNode (el) {
|
|
2140
|
-
const virtualNodeTagMap = ['block', 'template', 'import', config[mode].wxs.tag].reduce((map, item) => {
|
|
2154
|
+
const virtualNodeTagMap = ['block', 'template', 'import', 'slot', config[mode].wxs.tag].reduce((map, item) => {
|
|
2141
2155
|
map[item] = true
|
|
2142
2156
|
return map
|
|
2143
2157
|
}, {})
|
|
@@ -2145,7 +2159,11 @@ function isRealNode (el) {
|
|
|
2145
2159
|
}
|
|
2146
2160
|
|
|
2147
2161
|
function isComponentNode (el, options) {
|
|
2148
|
-
return
|
|
2162
|
+
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
function isReactComponent (el, options) {
|
|
2166
|
+
return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn
|
|
2149
2167
|
}
|
|
2150
2168
|
|
|
2151
2169
|
function processExternalClasses (el, options) {
|
|
@@ -2263,8 +2281,10 @@ function postProcessAliComponentRootView (el, options, meta) {
|
|
|
2263
2281
|
{ condition: /^style$/, action: 'move' },
|
|
2264
2282
|
{ condition: /^slot$/, action: 'move' }
|
|
2265
2283
|
]
|
|
2284
|
+
const tagName = el.tag
|
|
2285
|
+
const mid = options.usingComponentsInfo[tagName]?.mid || moduleId
|
|
2266
2286
|
const processAppendAttrsRules = [
|
|
2267
|
-
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${
|
|
2287
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` }
|
|
2268
2288
|
]
|
|
2269
2289
|
const newAttrs = []
|
|
2270
2290
|
const allAttrs = cloneAttrsList(el.attrsList)
|
|
@@ -2594,16 +2614,19 @@ function processElement (el, root, options, meta) {
|
|
|
2594
2614
|
}
|
|
2595
2615
|
|
|
2596
2616
|
if (isReact(mode)) {
|
|
2617
|
+
const pass = isReactComponent(el, options)
|
|
2597
2618
|
// 收集内建组件
|
|
2598
2619
|
processBuiltInComponents(el, meta)
|
|
2599
2620
|
// 预处理代码维度条件编译
|
|
2600
2621
|
processIf(el)
|
|
2601
2622
|
processFor(el)
|
|
2602
2623
|
processRefReact(el, meta)
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2624
|
+
if (!pass) {
|
|
2625
|
+
processStyleReact(el, options)
|
|
2626
|
+
processEventReact(el)
|
|
2627
|
+
processComponentIs(el, options)
|
|
2628
|
+
processSlotReact(el, meta)
|
|
2629
|
+
}
|
|
2607
2630
|
processAttrs(el, options)
|
|
2608
2631
|
return
|
|
2609
2632
|
}
|
|
@@ -2656,11 +2679,19 @@ function closeElement (el, meta, options) {
|
|
|
2656
2679
|
}
|
|
2657
2680
|
|
|
2658
2681
|
const isTemplate = postProcessTemplate(el) || processingTemplate
|
|
2659
|
-
if (!
|
|
2660
|
-
if (
|
|
2682
|
+
if (!isTemplate) {
|
|
2683
|
+
if (!isNative) {
|
|
2684
|
+
postProcessComponentIs(el, (child) => {
|
|
2685
|
+
if (!hasVirtualHost && mode === 'ali') {
|
|
2686
|
+
postProcessAliComponentRootView(child, options)
|
|
2687
|
+
} else {
|
|
2688
|
+
postProcessIf(child)
|
|
2689
|
+
}
|
|
2690
|
+
})
|
|
2691
|
+
}
|
|
2692
|
+
if (isComponentNode(el, options) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
|
|
2661
2693
|
postProcessAliComponentRootView(el, options, meta)
|
|
2662
2694
|
}
|
|
2663
|
-
postProcessComponentIs(el)
|
|
2664
2695
|
}
|
|
2665
2696
|
|
|
2666
2697
|
if (runtimeCompile) {
|
|
@@ -2707,7 +2738,7 @@ function cloneAttrsList (attrsList) {
|
|
|
2707
2738
|
})
|
|
2708
2739
|
}
|
|
2709
2740
|
|
|
2710
|
-
function postProcessComponentIs (el) {
|
|
2741
|
+
function postProcessComponentIs (el, postProcessChild) {
|
|
2711
2742
|
if (el.is && el.components) {
|
|
2712
2743
|
let tempNode
|
|
2713
2744
|
if (el.for || el.if || el.elseif || el.else) {
|
|
@@ -2729,7 +2760,7 @@ function postProcessComponentIs (el) {
|
|
|
2729
2760
|
})
|
|
2730
2761
|
newChild.exps = el.exps
|
|
2731
2762
|
addChild(tempNode, newChild)
|
|
2732
|
-
|
|
2763
|
+
postProcessChild(newChild)
|
|
2733
2764
|
})
|
|
2734
2765
|
|
|
2735
2766
|
if (!el.parent) {
|
|
@@ -56,8 +56,8 @@ function genNode (node) {
|
|
|
56
56
|
return map
|
|
57
57
|
}, {})
|
|
58
58
|
if (node.slot) {
|
|
59
|
-
const name = node.slot
|
|
60
|
-
exp += `__getSlot(${name ? s(name) : ''})`
|
|
59
|
+
const { name, slot } = node.slot
|
|
60
|
+
exp += `__getSlot(${name ? s(name) : ''}${slot ? `, ${s(slot)}` : ''})`
|
|
61
61
|
} else {
|
|
62
62
|
exp += `createElement(${`getComponent(${node.is || s(node.tag)})`}`
|
|
63
63
|
if (node.attrsList.length) {
|
|
@@ -24,14 +24,14 @@ module.exports = function (raw) {
|
|
|
24
24
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
25
25
|
const wxsContentMap = mpx.wxsContentMap
|
|
26
26
|
const optimizeRenderRules = mpx.optimizeRenderRules
|
|
27
|
-
const
|
|
27
|
+
const usingComponentsInfo = queryObj.usingComponentsInfo || {}
|
|
28
28
|
const componentPlaceholder = queryObj.componentPlaceholder || []
|
|
29
29
|
const hasComment = queryObj.hasComment
|
|
30
30
|
const isNative = queryObj.isNative
|
|
31
31
|
const ctorType = queryObj.ctorType
|
|
32
32
|
const hasScoped = queryObj.hasScoped
|
|
33
33
|
const runtimeCompile = queryObj.isDynamic
|
|
34
|
-
const moduleId = queryObj.moduleId ||
|
|
34
|
+
const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath)
|
|
35
35
|
|
|
36
36
|
let optimizeRenderLevel = 0
|
|
37
37
|
for (const rule of optimizeRenderRules) {
|
|
@@ -57,7 +57,6 @@ module.exports = function (raw) {
|
|
|
57
57
|
warn,
|
|
58
58
|
error,
|
|
59
59
|
runtimeCompile,
|
|
60
|
-
usingComponents,
|
|
61
60
|
componentPlaceholder,
|
|
62
61
|
hasComment,
|
|
63
62
|
isNative,
|
|
@@ -70,11 +69,12 @@ module.exports = function (raw) {
|
|
|
70
69
|
externalClasses,
|
|
71
70
|
hasScoped,
|
|
72
71
|
moduleId,
|
|
72
|
+
usingComponentsInfo,
|
|
73
73
|
// 这里需传递resourcePath和wxsContentMap保持一致
|
|
74
74
|
filePath: resourcePath,
|
|
75
75
|
i18n,
|
|
76
76
|
checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
|
|
77
|
-
globalComponents: Object.keys(mpx.
|
|
77
|
+
globalComponents: Object.keys(mpx.globalComponents),
|
|
78
78
|
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules) || runtimeCompile,
|
|
79
79
|
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
|
|
80
80
|
dynamicTemplateRuleRunner: mpx.dynamicTemplateRuleRunner
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
2
|
+
const JSON5 = require('json5')
|
|
3
|
+
const isUrlRequest = require('./is-url-request')
|
|
4
|
+
const parseRequest = require('./parse-request')
|
|
5
|
+
const addQuery = require('./add-query')
|
|
6
|
+
const resolve = require('./resolve')
|
|
7
|
+
const getJSONContent = require('./get-json-content')
|
|
8
|
+
const getRulesRunner = require('../platform')
|
|
9
|
+
const async = require('async')
|
|
10
|
+
|
|
11
|
+
module.exports = function ({
|
|
12
|
+
json,
|
|
13
|
+
srcMode,
|
|
14
|
+
emitWarning,
|
|
15
|
+
emitError,
|
|
16
|
+
ctorType,
|
|
17
|
+
resourcePath,
|
|
18
|
+
loaderContext
|
|
19
|
+
}, callback) {
|
|
20
|
+
const mpx = loaderContext.getMpx()
|
|
21
|
+
const context = loaderContext.context
|
|
22
|
+
const mode = mpx.mode
|
|
23
|
+
const pagesMap = mpx.pagesMap
|
|
24
|
+
async.waterfall([
|
|
25
|
+
(callback) => {
|
|
26
|
+
getJSONContent(json, null, loaderContext, callback)
|
|
27
|
+
},
|
|
28
|
+
(jsonContent, callback) => {
|
|
29
|
+
if (!jsonContent) return callback(null, {})
|
|
30
|
+
let componentPlaceholder = []
|
|
31
|
+
let componentGenerics = {}
|
|
32
|
+
const usingComponentsInfo = {}
|
|
33
|
+
const usingComponents = {}
|
|
34
|
+
const finalCallback = (err) => {
|
|
35
|
+
if (err) return callback(err)
|
|
36
|
+
if (ctorType === 'app') {
|
|
37
|
+
// 在 rulesRunner 运行后保存全局注册组件
|
|
38
|
+
// todo 其余地方在使用mpx.globalComponents时存在缓存问题,要规避该问题需要在所有使用mpx.globalComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
|
|
39
|
+
// todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
|
|
40
|
+
loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(usingComponents, usingComponentsInfo, context))
|
|
41
|
+
}
|
|
42
|
+
callback(null, {
|
|
43
|
+
componentPlaceholder,
|
|
44
|
+
componentGenerics,
|
|
45
|
+
usingComponentsInfo: Object.assign({}, usingComponentsInfo, mpx.globalComponentsInfo),
|
|
46
|
+
jsonContent
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const ret = JSON5.parse(jsonContent)
|
|
51
|
+
const rulesMeta = {}
|
|
52
|
+
const rulesRunnerOptions = {
|
|
53
|
+
mode,
|
|
54
|
+
srcMode,
|
|
55
|
+
type: 'json',
|
|
56
|
+
waterfall: true,
|
|
57
|
+
warn: emitWarning,
|
|
58
|
+
error: emitError,
|
|
59
|
+
meta: rulesMeta
|
|
60
|
+
}
|
|
61
|
+
if (ctorType !== 'app') {
|
|
62
|
+
rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
|
|
63
|
+
}
|
|
64
|
+
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
65
|
+
try {
|
|
66
|
+
if (rulesRunner) rulesRunner(ret)
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return finalCallback(e)
|
|
69
|
+
}
|
|
70
|
+
// 不支持全局组件的平台,runRules 时会删除 app.json 中的 usingComponents, 同时 fillGlobalComponents 方法会对 rulesMeta 赋值 usingComponents,通过 rulesMeta 来重新获取 globalComponents
|
|
71
|
+
// page | component 时 直接获取 ret.usingComponents 内容
|
|
72
|
+
Object.assign(usingComponents, ret.usingComponents || rulesMeta.usingComponents)
|
|
73
|
+
|
|
74
|
+
if (ret.componentPlaceholder) {
|
|
75
|
+
componentPlaceholder = componentPlaceholder.concat(Object.values(ret.componentPlaceholder))
|
|
76
|
+
}
|
|
77
|
+
if (ret.componentGenerics) {
|
|
78
|
+
componentGenerics = Object.assign({}, ret.componentGenerics)
|
|
79
|
+
}
|
|
80
|
+
if (usingComponents) {
|
|
81
|
+
const setUsingComponentInfo = (name, moduleId) => {
|
|
82
|
+
usingComponentsInfo[name] = { mid: moduleId }
|
|
83
|
+
}
|
|
84
|
+
async.eachOf(usingComponents, (component, name, callback) => {
|
|
85
|
+
if (ctorType === 'app') {
|
|
86
|
+
usingComponents[name] = addQuery(component, {
|
|
87
|
+
context
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
if (!isUrlRequest(component)) {
|
|
91
|
+
const moduleId = mpx.getModuleId(component, ctorType === 'app')
|
|
92
|
+
setUsingComponentInfo(name, moduleId)
|
|
93
|
+
return callback()
|
|
94
|
+
}
|
|
95
|
+
resolve(context, component, loaderContext, (err, resource) => {
|
|
96
|
+
if (err) return callback(err)
|
|
97
|
+
const { rawResourcePath } = parseRequest(resource)
|
|
98
|
+
const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app')
|
|
99
|
+
setUsingComponentInfo(name, moduleId)
|
|
100
|
+
callback()
|
|
101
|
+
})
|
|
102
|
+
}, (err) => {
|
|
103
|
+
finalCallback(err)
|
|
104
|
+
})
|
|
105
|
+
} else {
|
|
106
|
+
finalCallback()
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
finalCallback(err)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
], callback)
|
|
113
|
+
}
|
package/lib/web/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const RecordLoaderContentDependency = require('../dependencies/RecordLoaderConte
|
|
|
8
8
|
|
|
9
9
|
module.exports = function ({
|
|
10
10
|
parts,
|
|
11
|
+
jsonContent,
|
|
11
12
|
loaderContext,
|
|
12
13
|
pagesMap,
|
|
13
14
|
componentsMap,
|
|
@@ -19,7 +20,7 @@ module.exports = function ({
|
|
|
19
20
|
hasScoped,
|
|
20
21
|
hasComment,
|
|
21
22
|
isNative,
|
|
22
|
-
|
|
23
|
+
usingComponentsInfo,
|
|
23
24
|
componentGenerics,
|
|
24
25
|
autoScope,
|
|
25
26
|
callback
|
|
@@ -27,7 +28,7 @@ module.exports = function ({
|
|
|
27
28
|
if (ctorType === 'app' && !queryObj.isApp) {
|
|
28
29
|
return async.waterfall([
|
|
29
30
|
(callback) => {
|
|
30
|
-
processJSON(
|
|
31
|
+
processJSON(jsonContent, {
|
|
31
32
|
loaderContext,
|
|
32
33
|
ctorType,
|
|
33
34
|
pagesMap,
|
|
@@ -68,7 +69,7 @@ module.exports = function ({
|
|
|
68
69
|
srcMode,
|
|
69
70
|
moduleId,
|
|
70
71
|
ctorType,
|
|
71
|
-
|
|
72
|
+
usingComponentsInfo,
|
|
72
73
|
componentGenerics
|
|
73
74
|
}, callback)
|
|
74
75
|
},
|
|
@@ -80,7 +81,7 @@ module.exports = function ({
|
|
|
80
81
|
}, callback)
|
|
81
82
|
},
|
|
82
83
|
(callback) => {
|
|
83
|
-
processJSON(
|
|
84
|
+
processJSON(jsonContent, {
|
|
84
85
|
loaderContext,
|
|
85
86
|
ctorType,
|
|
86
87
|
pagesMap,
|
package/lib/web/processJSON.js
CHANGED
|
@@ -12,9 +12,8 @@ const createJSONHelper = require('../json-compiler/helper')
|
|
|
12
12
|
const getRulesRunner = require('../platform/index')
|
|
13
13
|
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
14
14
|
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
15
|
-
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
16
15
|
|
|
17
|
-
module.exports = function (
|
|
16
|
+
module.exports = function (jsonContent, {
|
|
18
17
|
loaderContext,
|
|
19
18
|
ctorType,
|
|
20
19
|
pagesMap,
|
|
@@ -82,12 +81,11 @@ module.exports = function (json, {
|
|
|
82
81
|
|
|
83
82
|
const isApp = ctorType === 'app'
|
|
84
83
|
|
|
85
|
-
if (!
|
|
84
|
+
if (!jsonContent) {
|
|
86
85
|
return callback()
|
|
87
86
|
}
|
|
88
|
-
// 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
|
|
89
87
|
try {
|
|
90
|
-
jsonObj = JSON5.parse(
|
|
88
|
+
jsonObj = JSON5.parse(jsonContent)
|
|
91
89
|
// 处理runner
|
|
92
90
|
const rulesRunnerOptions = {
|
|
93
91
|
mode,
|
|
@@ -97,8 +95,8 @@ module.exports = function (json, {
|
|
|
97
95
|
warn: emitWarning,
|
|
98
96
|
error: emitError,
|
|
99
97
|
data: {
|
|
100
|
-
// polyfill global usingComponents
|
|
101
|
-
globalComponents: mpx.
|
|
98
|
+
// polyfill global usingComponents
|
|
99
|
+
globalComponents: mpx.globalComponents
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -111,12 +109,6 @@ module.exports = function (json, {
|
|
|
111
109
|
if (rulesRunner) {
|
|
112
110
|
rulesRunner(jsonObj)
|
|
113
111
|
}
|
|
114
|
-
if (isApp) {
|
|
115
|
-
// 收集全局组件
|
|
116
|
-
Object.assign(mpx.usingComponents, jsonObj.usingComponents)
|
|
117
|
-
// 在 rulesRunner 运行后保存全局注册组件
|
|
118
|
-
loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
|
|
119
|
-
}
|
|
120
112
|
} catch (e) {
|
|
121
113
|
return callback(e)
|
|
122
114
|
}
|
|
@@ -12,7 +12,7 @@ module.exports = function (template, {
|
|
|
12
12
|
srcMode,
|
|
13
13
|
moduleId,
|
|
14
14
|
ctorType,
|
|
15
|
-
|
|
15
|
+
usingComponentsInfo,
|
|
16
16
|
componentGenerics
|
|
17
17
|
}, callback) {
|
|
18
18
|
const mpx = loaderContext.getMpx()
|
|
@@ -73,7 +73,7 @@ module.exports = function (template, {
|
|
|
73
73
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
74
74
|
warn,
|
|
75
75
|
error,
|
|
76
|
-
|
|
76
|
+
usingComponentsInfo, // processTemplate中无其他地方使用,直接透传 string 类型
|
|
77
77
|
hasComment,
|
|
78
78
|
isNative,
|
|
79
79
|
ctorType,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.69",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@better-scroll/wheel": "^2.5.1",
|
|
29
29
|
"@better-scroll/zoom": "^2.5.1",
|
|
30
30
|
"@mpxjs/template-engine": "^2.8.7",
|
|
31
|
-
"@mpxjs/utils": "^2.9.
|
|
31
|
+
"@mpxjs/utils": "^2.9.69",
|
|
32
32
|
"acorn": "^8.11.3",
|
|
33
33
|
"acorn-walk": "^7.2.0",
|
|
34
34
|
"async": "^2.6.0",
|
|
@@ -82,7 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@ant-design/react-native": "^5.2.2",
|
|
85
|
-
"@
|
|
85
|
+
"@d11/react-native-fast-image": "^8.6.12",
|
|
86
|
+
"@mpxjs/api-proxy": "^2.9.69",
|
|
86
87
|
"@types/babel-traverse": "^6.25.4",
|
|
87
88
|
"@types/babel-types": "^7.0.4",
|
|
88
89
|
"@types/react": "^18.2.79",
|
|
@@ -97,5 +98,5 @@
|
|
|
97
98
|
"engines": {
|
|
98
99
|
"node": ">=14.14.0"
|
|
99
100
|
},
|
|
100
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "e23c51acc4c2ffdd31fcc6c27aae1aed42d1ade2"
|
|
101
102
|
}
|