@mpxjs/webpack-plugin 2.10.6-beta.2 → 2.10.6-beta.3
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/index.js +22 -10
- package/lib/platform/index.js +2 -4
- package/lib/platform/template/wx/component-config/index.js +2 -2
- package/lib/platform/template/wx/component-config/template.js +1 -26
- package/lib/platform/template/wx/index.js +3 -10
- package/lib/react/LoadAsyncChunkModule.js +68 -0
- package/lib/react/index.js +3 -1
- package/lib/react/processJSON.js +6 -6
- package/lib/react/processScript.js +4 -3
- package/lib/react/script-helper.js +97 -18
- package/lib/runtime/components/react/AsyncContainer.tsx +189 -0
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-input.tsx +1 -1
- package/lib/runtime/components/react/mpx-movable-view.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +2 -2
- package/lib/runtime/components/react/mpx-swiper.tsx +53 -18
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -33
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/optionProcessor.js +2 -2
- package/lib/template-compiler/compiler.js +9 -59
- package/lib/utils/dom-tag-config.js +15 -1
- package/lib/web/index.js +0 -2
- package/lib/web/processScript.js +7 -29
- package/lib/web/processTemplate.js +4 -10
- package/lib/web/script-helper.js +1 -1
- package/package.json +1 -1
- package/lib/dependencies/WriteVfsDependency.js +0 -46
- package/lib/utils/get-template-content.js +0 -47
- package/lib/web/template2vue.js +0 -280
- package/lib/web/wxml-template-loader.js +0 -29
|
@@ -16,7 +16,6 @@ const setBaseWxml = require('../runtime-render/base-wxml')
|
|
|
16
16
|
const { parseExp } = require('./parse-exps')
|
|
17
17
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
18
18
|
const { isReact, isWeb } = require('../utils/env')
|
|
19
|
-
const getTemplateContent = require('../utils/get-template-content')
|
|
20
19
|
|
|
21
20
|
const no = function () {
|
|
22
21
|
return false
|
|
@@ -639,7 +638,7 @@ function parse (template, options) {
|
|
|
639
638
|
componentGenerics = options.componentGenerics || {}
|
|
640
639
|
|
|
641
640
|
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
642
|
-
usingComponents = Object.keys(options.usingComponentsInfo
|
|
641
|
+
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
643
642
|
usingComponentsInfo = options.usingComponentsInfo
|
|
644
643
|
|
|
645
644
|
const _warn = content => {
|
|
@@ -662,7 +661,6 @@ function parse (template, options) {
|
|
|
662
661
|
srcMode,
|
|
663
662
|
type: 'template',
|
|
664
663
|
testKey: 'tag',
|
|
665
|
-
moduleId,
|
|
666
664
|
data: {
|
|
667
665
|
usingComponents
|
|
668
666
|
},
|
|
@@ -691,7 +689,6 @@ function parse (template, options) {
|
|
|
691
689
|
root = currentParent = getVirtualHostRoot(options, meta)
|
|
692
690
|
stack.push(root)
|
|
693
691
|
}
|
|
694
|
-
options.template = template // processTemplate时需要对template(只用于处理含name的情况)做截取
|
|
695
692
|
|
|
696
693
|
parseHTML(template, {
|
|
697
694
|
warn: warn$1,
|
|
@@ -724,7 +721,6 @@ function parse (template, options) {
|
|
|
724
721
|
|
|
725
722
|
currentParent.children.push(element)
|
|
726
723
|
element.parent = currentParent
|
|
727
|
-
|
|
728
724
|
processElement(element, root, options, meta)
|
|
729
725
|
|
|
730
726
|
tagNames.add(element.tag)
|
|
@@ -1430,6 +1426,7 @@ function processEvent (el, options) {
|
|
|
1430
1426
|
}
|
|
1431
1427
|
}
|
|
1432
1428
|
})
|
|
1429
|
+
|
|
1433
1430
|
addAttrs(el, [
|
|
1434
1431
|
{
|
|
1435
1432
|
name: resultName || config[mode].event.getEvent(type),
|
|
@@ -1465,13 +1462,6 @@ function wrapMustache (val) {
|
|
|
1465
1462
|
return val && !tagRE.test(val) ? `{{${val}}}` : val
|
|
1466
1463
|
}
|
|
1467
1464
|
|
|
1468
|
-
function vbindMustache (val) {
|
|
1469
|
-
const bindREG = /\{\{((?:.|\n|\r|\.{3})+?)\}\}(?!})/
|
|
1470
|
-
const match = bindREG.exec(val) || []
|
|
1471
|
-
const matchStr = match[1]?.trim()
|
|
1472
|
-
return matchStr ? `{${matchStr}}` : val
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
1465
|
function parseOptionalChaining (str) {
|
|
1476
1466
|
const wxsName = `${optionalChainWxsName}.g`
|
|
1477
1467
|
let optionsRes
|
|
@@ -2312,7 +2302,7 @@ function processExternalClasses (el, options) {
|
|
|
2312
2302
|
let classNames = classLikeAttrValue.split(/\s+/)
|
|
2313
2303
|
let hasExternalClass = false
|
|
2314
2304
|
classNames = classNames.map((className) => {
|
|
2315
|
-
if (options.externalClasses
|
|
2305
|
+
if (options.externalClasses.includes(className)) {
|
|
2316
2306
|
hasExternalClass = true
|
|
2317
2307
|
return `($attrs[${stringify(className)}] || '')`
|
|
2318
2308
|
}
|
|
@@ -2355,12 +2345,12 @@ function processExternalClasses (el, options) {
|
|
|
2355
2345
|
}
|
|
2356
2346
|
|
|
2357
2347
|
function processScoped (el) {
|
|
2358
|
-
if (hasScoped && isRealNode(el)
|
|
2348
|
+
if (hasScoped && isRealNode(el)) {
|
|
2359
2349
|
const rootModuleId = ctorType === 'component' ? '' : MPX_APP_MODULE_ID // 处理app全局样式对页面的影响
|
|
2360
2350
|
const staticClass = getAndRemoveAttr(el, 'class').val
|
|
2361
2351
|
addAttrs(el, [{
|
|
2362
2352
|
name: 'class',
|
|
2363
|
-
value: `${staticClass || ''} ${moduleId
|
|
2353
|
+
value: `${staticClass || ''} ${moduleId} ${rootModuleId}`
|
|
2364
2354
|
}])
|
|
2365
2355
|
}
|
|
2366
2356
|
}
|
|
@@ -2459,7 +2449,7 @@ function getVirtualHostRoot (options, meta) {
|
|
|
2459
2449
|
const rootView = createASTElement('view', [
|
|
2460
2450
|
{
|
|
2461
2451
|
name: 'class',
|
|
2462
|
-
value: `${MPX_ROOT_VIEW}
|
|
2452
|
+
value: `${MPX_ROOT_VIEW} host-${moduleId}`
|
|
2463
2453
|
},
|
|
2464
2454
|
{
|
|
2465
2455
|
name: 'v-on',
|
|
@@ -2538,33 +2528,8 @@ function processTemplate (el) {
|
|
|
2538
2528
|
}
|
|
2539
2529
|
}
|
|
2540
2530
|
|
|
2541
|
-
function
|
|
2542
|
-
if (el.tag === 'import' && el.attrsMap.src) {
|
|
2543
|
-
if (!meta.templateSrcList) {
|
|
2544
|
-
meta.templateSrcList = []
|
|
2545
|
-
}
|
|
2546
|
-
if (!meta.templateSrcList.includes(el.attrsMap.src)) {
|
|
2547
|
-
meta.templateSrcList.push(el.attrsMap.src)
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
|
|
2552
|
-
function postProcessTemplate (el, meta, options) {
|
|
2531
|
+
function postProcessTemplate (el) {
|
|
2553
2532
|
if (el.isTemplate) {
|
|
2554
|
-
if (mode === 'web') {
|
|
2555
|
-
if (!meta.inlineTemplateMap) {
|
|
2556
|
-
meta.inlineTemplateMap = {}
|
|
2557
|
-
}
|
|
2558
|
-
const name = el.attrsMap.name // 行内的template有name就收集template的内容和给内容生成一个地址
|
|
2559
|
-
if (name) {
|
|
2560
|
-
const content = getTemplateContent(options.template, name)
|
|
2561
|
-
const filePath = options.filePath.replace(/.mpx$/, `-${name}.wxml`)
|
|
2562
|
-
meta.inlineTemplateMap[name] = {
|
|
2563
|
-
filePath,
|
|
2564
|
-
content
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
2533
|
processingTemplate = false
|
|
2569
2534
|
return true
|
|
2570
2535
|
}
|
|
@@ -2714,7 +2679,6 @@ function processMpxTagName (el) {
|
|
|
2714
2679
|
}
|
|
2715
2680
|
|
|
2716
2681
|
function processElement (el, root, options, meta) {
|
|
2717
|
-
const initialTag = el.tag // 预存,在这个阶段增加_fakeTemplate值会影响web小程序元素trans web元素
|
|
2718
2682
|
processAtMode(el)
|
|
2719
2683
|
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
|
|
2720
2684
|
if (el._matchStatus === statusEnum.MISMATCH) {
|
|
@@ -2741,17 +2705,10 @@ function processElement (el, root, options, meta) {
|
|
|
2741
2705
|
const transAli = mode === 'ali' && srcMode === 'wx'
|
|
2742
2706
|
|
|
2743
2707
|
if (isWeb(mode)) {
|
|
2744
|
-
if (initialTag === 'block') {
|
|
2745
|
-
el._fakeTemplate = true // 该值是在template2vue中处理block转换的template的情况
|
|
2746
|
-
}
|
|
2747
2708
|
// 收集内建组件
|
|
2748
2709
|
processBuiltInComponents(el, meta)
|
|
2749
2710
|
// 预处理代码维度条件编译
|
|
2750
2711
|
processIfWeb(el)
|
|
2751
|
-
// 预处理template逻辑
|
|
2752
|
-
processTemplate(el)
|
|
2753
|
-
// 预处理import逻辑
|
|
2754
|
-
processImport(el, meta)
|
|
2755
2712
|
processScoped(el)
|
|
2756
2713
|
processEventWeb(el)
|
|
2757
2714
|
// processWebExternalClassesHack(el, options)
|
|
@@ -2814,9 +2771,8 @@ function processElement (el, root, options, meta) {
|
|
|
2814
2771
|
function closeElement (el, options, meta) {
|
|
2815
2772
|
postProcessAtMode(el)
|
|
2816
2773
|
postProcessWxs(el, meta)
|
|
2774
|
+
|
|
2817
2775
|
if (isWeb(mode)) {
|
|
2818
|
-
// 处理web下template逻辑
|
|
2819
|
-
postProcessTemplate(el, meta, options)
|
|
2820
2776
|
// 处理代码维度条件编译移除死分支
|
|
2821
2777
|
postProcessIf(el)
|
|
2822
2778
|
return
|
|
@@ -2827,7 +2783,7 @@ function closeElement (el, options, meta) {
|
|
|
2827
2783
|
return
|
|
2828
2784
|
}
|
|
2829
2785
|
|
|
2830
|
-
const isTemplate = postProcessTemplate(el
|
|
2786
|
+
const isTemplate = postProcessTemplate(el) || processingTemplate
|
|
2831
2787
|
if (!isTemplate) {
|
|
2832
2788
|
if (!isNative) {
|
|
2833
2789
|
postProcessComponentIs(el, (child) => {
|
|
@@ -2949,11 +2905,6 @@ function serialize (root) {
|
|
|
2949
2905
|
result += node.text
|
|
2950
2906
|
}
|
|
2951
2907
|
}
|
|
2952
|
-
if (mode === 'web') {
|
|
2953
|
-
if ((node.tag === 'template' && node.attrsMap && node.attrsMap.name) || node.tag === 'import') {
|
|
2954
|
-
return result
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
2908
|
|
|
2958
2909
|
if (node.type === 1) {
|
|
2959
2910
|
if (node.tag !== 'temp-node') {
|
|
@@ -3258,7 +3209,6 @@ module.exports = {
|
|
|
3258
3209
|
genNode,
|
|
3259
3210
|
makeAttrsMap,
|
|
3260
3211
|
stringifyAttr,
|
|
3261
|
-
vbindMustache,
|
|
3262
3212
|
parseMustache,
|
|
3263
3213
|
parseMustacheWithContext,
|
|
3264
3214
|
stringifyWithResolveComputed,
|
|
@@ -81,6 +81,19 @@ const isBuildInTag = makeMap(
|
|
|
81
81
|
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* 是否为mpx2rn内置组件
|
|
86
|
+
*/
|
|
87
|
+
const isBuildInReactTag = makeMap(
|
|
88
|
+
'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
|
|
89
|
+
'mpx-swiper,mpx-swiper-item,mpx-simple-view,mpx-simple-text,mpx-scroll-view,' +
|
|
90
|
+
'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
|
|
91
|
+
'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
|
|
92
|
+
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
|
+
'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
|
+
'mpx-icon,mpx-canvas'
|
|
95
|
+
)
|
|
96
|
+
|
|
84
97
|
const isSpace = makeMap('ensp,emsp,nbsp')
|
|
85
98
|
|
|
86
99
|
const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
|
|
@@ -111,5 +124,6 @@ module.exports = {
|
|
|
111
124
|
isContWidth,
|
|
112
125
|
isContHeight,
|
|
113
126
|
isNativeMiniTag,
|
|
114
|
-
isContConRow
|
|
127
|
+
isContConRow,
|
|
128
|
+
isBuildInReactTag
|
|
115
129
|
}
|
package/lib/web/index.js
CHANGED
|
@@ -108,8 +108,6 @@ module.exports = function ({
|
|
|
108
108
|
builtInComponentsMap: templateRes.builtInComponentsMap,
|
|
109
109
|
genericsInfo: templateRes.genericsInfo,
|
|
110
110
|
wxsModuleMap: templateRes.wxsModuleMap,
|
|
111
|
-
templateSrcList: templateRes.templateSrcList,
|
|
112
|
-
inlineTemplateMap: templateRes.inlineTemplateMap,
|
|
113
111
|
localComponentsMap: jsonRes.localComponentsMap
|
|
114
112
|
}, callback)
|
|
115
113
|
}
|
package/lib/web/processScript.js
CHANGED
|
@@ -3,8 +3,6 @@ const loaderUtils = require('loader-utils')
|
|
|
3
3
|
const normalize = require('../utils/normalize')
|
|
4
4
|
const shallowStringify = require('../utils/shallow-stringify')
|
|
5
5
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
6
|
-
const wxmlTemplateLoader = normalize.lib('web/wxml-template-loader')
|
|
7
|
-
const WriteVfsDependency = require('../dependencies/WriteVfsDependency')
|
|
8
6
|
const {
|
|
9
7
|
buildComponentsMap,
|
|
10
8
|
getRequireScript,
|
|
@@ -24,20 +22,18 @@ module.exports = function (script, {
|
|
|
24
22
|
builtInComponentsMap,
|
|
25
23
|
genericsInfo,
|
|
26
24
|
wxsModuleMap,
|
|
27
|
-
templateSrcList,
|
|
28
|
-
inlineTemplateMap,
|
|
29
25
|
localComponentsMap
|
|
30
26
|
}, callback) {
|
|
31
|
-
const { projectRoot, appInfo, webConfig
|
|
27
|
+
const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()
|
|
32
28
|
|
|
33
29
|
let output = '/* script */\n'
|
|
30
|
+
|
|
34
31
|
let scriptSrcMode = srcMode
|
|
35
32
|
if (script) {
|
|
36
33
|
scriptSrcMode = script.mode || scriptSrcMode
|
|
37
34
|
} else {
|
|
38
35
|
script = { tag: 'script' }
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
output += genComponentTag(script, {
|
|
42
38
|
attrs (script) {
|
|
43
39
|
const attrs = Object.assign({}, script.attrs)
|
|
@@ -62,36 +58,17 @@ module.exports = function (script, {
|
|
|
62
58
|
content += ` wxsModules.${module} = ${expression}\n`
|
|
63
59
|
})
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
if (templateSrcList?.length) { // import标签处理
|
|
67
|
-
templateSrcList?.forEach((item) => {
|
|
68
|
-
content += `
|
|
69
|
-
const tempLoaderResult = require(${stringifyRequest(this, `!!${wxmlTemplateLoader}!${item}`)})\n
|
|
70
|
-
Object.assign(templateModules, tempLoaderResult)\n`
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
// 把wxml要的localComponentsMap merge到parentLocalComponentsMap中这样在 template2vue中就可以拿到对应的值
|
|
74
|
-
Object.assign(parentLocalComponentsMap, localComponentsMap)
|
|
61
|
+
|
|
75
62
|
// 获取组件集合
|
|
76
63
|
const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })
|
|
64
|
+
|
|
77
65
|
// 获取pageConfig
|
|
78
66
|
const pageConfig = {}
|
|
79
67
|
if (ctorType === 'page') {
|
|
80
68
|
Object.assign(pageConfig, jsonConfig)
|
|
81
69
|
delete pageConfig.usingComponents
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
const inlineTemplateMapLists = Object.keys(inlineTemplateMap)
|
|
85
|
-
if (inlineTemplateMapLists.length) {
|
|
86
|
-
inlineTemplateMapLists.forEach((name) => {
|
|
87
|
-
const { filePath, content } = inlineTemplateMap[name]
|
|
88
|
-
loaderContext._module.addPresentationalDependency(new WriteVfsDependency(filePath, content)) // 处理缓存报错的情况
|
|
89
|
-
vfs.writeModule(filePath, content) // 截取template写入文件
|
|
90
|
-
const expression = `getComponent(require(${stringifyRequest(loaderContext, `${filePath}?is=${name}&localComponentsMap=${encodeURIComponent(JSON.stringify(localComponentsMap))}&isTemplate`)}))`
|
|
91
|
-
componentsMap[name] = expression
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
}
|
|
71
|
+
|
|
95
72
|
content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
|
|
96
73
|
content += getRequireScript({ ctorType, script, loaderContext })
|
|
97
74
|
content += `
|
|
@@ -101,7 +78,7 @@ module.exports = function (script, {
|
|
|
101
78
|
outputPath: ${JSON.stringify(outputPath)},
|
|
102
79
|
pageConfig: ${JSON.stringify(pageConfig)},
|
|
103
80
|
// @ts-ignore
|
|
104
|
-
componentsMap:
|
|
81
|
+
componentsMap: ${shallowStringify(componentsMap)},
|
|
105
82
|
componentGenerics: ${JSON.stringify(componentGenerics)},
|
|
106
83
|
genericsInfo: ${JSON.stringify(genericsInfo)},
|
|
107
84
|
wxsMixin: getWxsMixin(wxsModules),
|
|
@@ -110,6 +87,7 @@ module.exports = function (script, {
|
|
|
110
87
|
return content
|
|
111
88
|
}
|
|
112
89
|
})
|
|
90
|
+
|
|
113
91
|
callback(null, {
|
|
114
92
|
output
|
|
115
93
|
})
|
|
@@ -31,7 +31,7 @@ module.exports = function (template, {
|
|
|
31
31
|
const { resourcePath, rawResourcePath } = parseRequest(loaderContext.resource)
|
|
32
32
|
const builtInComponentsMap = {}
|
|
33
33
|
|
|
34
|
-
let wxsModuleMap, genericsInfo
|
|
34
|
+
let wxsModuleMap, genericsInfo
|
|
35
35
|
let output = '/* template */\n'
|
|
36
36
|
|
|
37
37
|
if (ctorType === 'app') {
|
|
@@ -54,6 +54,7 @@ module.exports = function (template, {
|
|
|
54
54
|
if (template.lang) {
|
|
55
55
|
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
|
|
56
56
|
}
|
|
57
|
+
|
|
57
58
|
output += genComponentTag(template, (template) => {
|
|
58
59
|
if (ctorType === 'app') {
|
|
59
60
|
return template.content
|
|
@@ -103,12 +104,6 @@ module.exports = function (template, {
|
|
|
103
104
|
wxsContentMap[`${rawResourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
if (meta.inlineTemplateMap) {
|
|
107
|
-
inlineTemplateMap = meta.inlineTemplateMap
|
|
108
|
-
}
|
|
109
|
-
if (meta.templateSrcList?.length) {
|
|
110
|
-
templateSrcList = meta.templateSrcList
|
|
111
|
-
}
|
|
112
107
|
if (meta.builtInComponentsMap) {
|
|
113
108
|
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
114
109
|
builtInComponentsMap[name] = {
|
|
@@ -119,16 +114,15 @@ module.exports = function (template, {
|
|
|
119
114
|
if (meta.genericsInfo) {
|
|
120
115
|
genericsInfo = meta.genericsInfo
|
|
121
116
|
}
|
|
122
|
-
return templateCompiler.serialize(root
|
|
117
|
+
return templateCompiler.serialize(root)
|
|
123
118
|
}
|
|
124
119
|
})
|
|
125
120
|
output += '\n'
|
|
126
121
|
}
|
|
122
|
+
|
|
127
123
|
callback(null, {
|
|
128
124
|
output,
|
|
129
125
|
builtInComponentsMap,
|
|
130
|
-
inlineTemplateMap,
|
|
131
|
-
templateSrcList,
|
|
132
126
|
genericsInfo,
|
|
133
127
|
wxsModuleMap
|
|
134
128
|
})
|
package/lib/web/script-helper.js
CHANGED
|
@@ -13,7 +13,7 @@ function stringifyRequest (loaderContext, request) {
|
|
|
13
13
|
|
|
14
14
|
function getAsyncChunkName (chunkName) {
|
|
15
15
|
if (chunkName && typeof chunkName !== 'boolean') {
|
|
16
|
-
return `/* webpackChunkName: "${chunkName}" */`
|
|
16
|
+
return `/* webpackChunkName: "${chunkName}/index" */`
|
|
17
17
|
}
|
|
18
18
|
return ''
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
-
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
-
|
|
4
|
-
class WriteVfsDependency extends NullDependency {
|
|
5
|
-
constructor (filename, content) {
|
|
6
|
-
super()
|
|
7
|
-
this.filename = filename
|
|
8
|
-
this.content = content
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get type () {
|
|
12
|
-
return 'mpx app entry'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
mpxAction (module, compilation, callback) {
|
|
16
|
-
const mpx = compilation.__mpx__
|
|
17
|
-
const vfs = mpx.__vfs
|
|
18
|
-
if (vfs) {
|
|
19
|
-
vfs.writeModule(this.filename, this.content)
|
|
20
|
-
}
|
|
21
|
-
return callback()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
serialize (context) {
|
|
25
|
-
const { write } = context
|
|
26
|
-
write(this.filename)
|
|
27
|
-
write(this.content)
|
|
28
|
-
super.serialize(context)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
deserialize (context) {
|
|
32
|
-
const { read } = context
|
|
33
|
-
this.filename = read()
|
|
34
|
-
this.content = read()
|
|
35
|
-
super.deserialize(context)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
WriteVfsDependency.Template = class WriteVfsDependencyTemplate {
|
|
40
|
-
apply () {
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
makeSerializable(WriteVfsDependency, '@mpxjs/webpack-plugin/lib/dependencies/WriteVfsDependency')
|
|
45
|
-
|
|
46
|
-
module.exports = WriteVfsDependency
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
对template.wxml文件做截取
|
|
3
|
-
@source原始小程序文件
|
|
4
|
-
@name 要匹配的该name的template
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function (source, name) {
|
|
7
|
-
// 使用正则表达式匹配具有 name 的 template 标签及其所有子元素
|
|
8
|
-
// 正则表达式使用非贪婪匹配来递归匹配嵌套的 template
|
|
9
|
-
const regex = new RegExp(`(<template[^>]*\\bname=["|']${name}["|'][^>]*>).*?`, 'g')
|
|
10
|
-
|
|
11
|
-
let startIndex = 0
|
|
12
|
-
let endIndex = 0
|
|
13
|
-
const match = regex.exec(source)
|
|
14
|
-
// 逐个处理匹配到的 template 标签及其内容
|
|
15
|
-
if (match) {
|
|
16
|
-
const matchRes = match[0]
|
|
17
|
-
const reg = /<\/?template\s*[^>]*>/g
|
|
18
|
-
let n = 0
|
|
19
|
-
startIndex = match.index
|
|
20
|
-
endIndex = startIndex + matchRes.length
|
|
21
|
-
let html = source.slice(endIndex)
|
|
22
|
-
while (html) {
|
|
23
|
-
const matchRes = html.match(reg)
|
|
24
|
-
if (matchRes.length) {
|
|
25
|
-
const matchTemp = matchRes[0]
|
|
26
|
-
const matchIndex = html.indexOf(matchTemp)
|
|
27
|
-
const matchLength = matchTemp.length
|
|
28
|
-
const cutLength = matchIndex + matchLength
|
|
29
|
-
if (matchTemp.startsWith('</template>')) {
|
|
30
|
-
if (n === 0) {
|
|
31
|
-
endIndex += cutLength
|
|
32
|
-
break
|
|
33
|
-
} else {
|
|
34
|
-
n--
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
n++
|
|
38
|
-
}
|
|
39
|
-
endIndex += cutLength
|
|
40
|
-
html = html.slice(cutLength)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
return ''
|
|
45
|
-
}
|
|
46
|
-
return source.slice(startIndex, endIndex)
|
|
47
|
-
}
|