@mpxjs/webpack-plugin 2.9.18 → 2.9.19-react.0
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/config.js +59 -97
- package/lib/dependencies/ResolveDependency.js +2 -2
- package/lib/helpers.js +5 -1
- package/lib/index.js +21 -18
- package/lib/loader.js +44 -97
- package/lib/native-loader.js +1 -1
- package/lib/platform/index.js +3 -0
- package/lib/platform/style/wx/index.js +413 -0
- package/lib/platform/template/wx/component-config/button.js +36 -0
- package/lib/platform/template/wx/component-config/image.js +15 -0
- package/lib/platform/template/wx/component-config/input.js +36 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
- package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
- package/lib/platform/template/wx/component-config/swiper.js +25 -1
- package/lib/platform/template/wx/component-config/text.js +15 -0
- package/lib/platform/template/wx/component-config/textarea.js +39 -0
- package/lib/platform/template/wx/component-config/unsupported.js +18 -0
- package/lib/platform/template/wx/component-config/view.js +14 -0
- package/lib/platform/template/wx/index.js +88 -4
- package/lib/react/index.js +92 -0
- package/lib/react/processJSON.js +362 -0
- package/lib/react/processScript.js +40 -0
- package/lib/react/processStyles.js +63 -0
- package/lib/react/processTemplate.js +151 -0
- package/lib/react/script-helper.js +79 -0
- package/lib/react/style-helper.js +91 -0
- package/lib/runtime/components/react/event.config.ts +32 -0
- package/lib/runtime/components/react/getInnerListeners.ts +289 -0
- package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
- package/lib/runtime/components/react/mpx-button.tsx +402 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
- package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
- package/lib/runtime/components/react/mpx-input.tsx +389 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +407 -0
- package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
- package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
- package/lib/runtime/components/react/mpx-text.tsx +106 -0
- package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
- package/lib/runtime/components/react/mpx-view.tsx +397 -0
- package/lib/runtime/components/react/utils.ts +92 -0
- package/lib/runtime/stringify.wxs +3 -7
- package/lib/runtime/useNodesRef.ts +39 -0
- package/lib/style-compiler/index.js +2 -1
- package/lib/template-compiler/compiler.js +539 -287
- package/lib/template-compiler/gen-node-react.js +95 -0
- package/lib/template-compiler/index.js +19 -31
- package/lib/utils/env.js +17 -0
- package/lib/utils/make-map.js +1 -1
- package/lib/utils/shallow-stringify.js +17 -0
- package/lib/web/index.js +122 -0
- package/lib/web/processMainScript.js +3 -4
- package/lib/web/processScript.js +9 -5
- package/lib/web/processTemplate.js +14 -14
- package/lib/web/script-helper.js +11 -19
- package/package.json +7 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
2
|
+
|
|
3
|
+
function genIf (node) {
|
|
4
|
+
node.ifProcessed = true
|
|
5
|
+
return genIfConditions(node.ifConditions.slice())
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function genIfConditions (conditions) {
|
|
9
|
+
if (!conditions.length) return 'null'
|
|
10
|
+
const condition = conditions.shift()
|
|
11
|
+
if (condition.exp) {
|
|
12
|
+
return `(${condition.exp})?${genNode(condition.block)}:${genIfConditions(conditions)}`
|
|
13
|
+
} else {
|
|
14
|
+
return genNode(condition.block)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function genFor (node) {
|
|
19
|
+
node.forProcessed = true
|
|
20
|
+
const index = node.for.index || 'index'
|
|
21
|
+
const item = node.for.item || 'item'
|
|
22
|
+
return `_i(${node.for.exp}, function(${item},${index}){return ${genNode(node)}})`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const s = JSON.stringify
|
|
26
|
+
|
|
27
|
+
function mapAttrName (name) {
|
|
28
|
+
if (name === 'class') return 'className'
|
|
29
|
+
if (!isValidIdentifierStr(name)) return s(name)
|
|
30
|
+
return name
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function genNode (node) {
|
|
34
|
+
let exp = ''
|
|
35
|
+
if (node) {
|
|
36
|
+
if (node.type === 3) {
|
|
37
|
+
if (!node.isComment) {
|
|
38
|
+
if (node.exps) {
|
|
39
|
+
exp += `${node.exps[0].exp}`
|
|
40
|
+
} else {
|
|
41
|
+
exp += `${s(node.text)}`
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (node.type === 1) {
|
|
46
|
+
if (node.tag !== 'temp-node') {
|
|
47
|
+
if (node.for && !node.forProcessed) {
|
|
48
|
+
exp += genFor(node)
|
|
49
|
+
} else if (node.if && !node.ifProcessed) {
|
|
50
|
+
exp += genIf(node)
|
|
51
|
+
} else {
|
|
52
|
+
const attrExpMap = (node.exps || []).reduce((map, { exp, attrName }) => {
|
|
53
|
+
if (attrName) {
|
|
54
|
+
map[attrName] = exp
|
|
55
|
+
}
|
|
56
|
+
return map
|
|
57
|
+
}, {})
|
|
58
|
+
if (node.slot) {
|
|
59
|
+
const name = node.slot.name
|
|
60
|
+
exp += `__getSlot(${name ? s(name) : ''})`
|
|
61
|
+
} else {
|
|
62
|
+
exp += `createElement(${node.isComponent || node.isBuiltIn ? `components[${node.is || s(node.tag)}]` : `getNativeComponent(${s(node.tag)})`}`
|
|
63
|
+
if (node.isRoot) {
|
|
64
|
+
exp += `, Object.assign({}, rootProps, {style: [${attrExpMap.style}, rootProps.style]})`
|
|
65
|
+
} else if (node.attrsList.length) {
|
|
66
|
+
const attrs = []
|
|
67
|
+
node.attrsList && node.attrsList.forEach(({ name, value }) => {
|
|
68
|
+
const attrExp = attrExpMap[name] ? attrExpMap[name] : s(value)
|
|
69
|
+
attrs.push(`${mapAttrName(name)}: ${attrExp}`)
|
|
70
|
+
})
|
|
71
|
+
exp += `, { ${attrs.join(', ')} }`
|
|
72
|
+
} else {
|
|
73
|
+
exp += ', null'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!node.unary && node.children.length) {
|
|
77
|
+
exp += ','
|
|
78
|
+
node.children.forEach(function (child, index) {
|
|
79
|
+
exp += `${index === 0 ? '' : ','}${genNode(child)}`
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
exp += ')'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
node.children.forEach(function (child, index) {
|
|
87
|
+
exp += `${index === 0 ? '' : ','}${genNode(child)}`
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return exp
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = genNode
|
|
@@ -8,7 +8,7 @@ module.exports = function (raw) {
|
|
|
8
8
|
this.cacheable()
|
|
9
9
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
10
10
|
const mpx = this.getMpx()
|
|
11
|
-
const
|
|
11
|
+
const projectRoot = mpx.projectRoot
|
|
12
12
|
const mode = mpx.mode
|
|
13
13
|
const env = mpx.env
|
|
14
14
|
const defs = mpx.defs
|
|
@@ -17,15 +17,13 @@ module.exports = function (raw) {
|
|
|
17
17
|
const decodeHTMLText = mpx.decodeHTMLText
|
|
18
18
|
const globalSrcMode = mpx.srcMode
|
|
19
19
|
const localSrcMode = queryObj.mode
|
|
20
|
-
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
21
|
-
const componentsMap = mpx.componentsMap[packageName]
|
|
22
|
-
const pagesMap = mpx.pagesMap
|
|
23
20
|
const wxsContentMap = mpx.wxsContentMap
|
|
24
21
|
const optimizeRenderRules = mpx.optimizeRenderRules
|
|
25
22
|
const usingComponents = queryObj.usingComponents || []
|
|
26
23
|
const componentPlaceholder = queryObj.componentPlaceholder || []
|
|
27
24
|
const hasComment = queryObj.hasComment
|
|
28
25
|
const isNative = queryObj.isNative
|
|
26
|
+
const ctorType = queryObj.ctorType
|
|
29
27
|
const hasScoped = queryObj.hasScoped
|
|
30
28
|
const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
|
|
31
29
|
|
|
@@ -36,6 +34,7 @@ module.exports = function (raw) {
|
|
|
36
34
|
break
|
|
37
35
|
}
|
|
38
36
|
}
|
|
37
|
+
|
|
39
38
|
const warn = (msg) => {
|
|
40
39
|
this.emitWarning(
|
|
41
40
|
new Error('[template compiler][' + this.resource + ']: ' + msg)
|
|
@@ -48,15 +47,14 @@ module.exports = function (raw) {
|
|
|
48
47
|
)
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
const { root
|
|
50
|
+
const { root, meta } = compiler.parse(raw, {
|
|
52
51
|
warn,
|
|
53
52
|
error,
|
|
54
53
|
usingComponents,
|
|
55
54
|
componentPlaceholder,
|
|
56
55
|
hasComment,
|
|
57
56
|
isNative,
|
|
58
|
-
|
|
59
|
-
isPage: !!pagesMap[resourcePath],
|
|
57
|
+
ctorType,
|
|
60
58
|
mode,
|
|
61
59
|
env,
|
|
62
60
|
srcMode: localSrcMode || globalSrcMode,
|
|
@@ -80,25 +78,23 @@ module.exports = function (raw) {
|
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
|
|
81
|
+
const result = compiler.serialize(root)
|
|
82
|
+
if (isNative) {
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
83
86
|
let resultSource = ''
|
|
84
87
|
|
|
85
88
|
for (const module in meta.wxsModuleMap) {
|
|
86
|
-
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module],
|
|
89
|
+
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
|
|
87
90
|
resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (isNative) {
|
|
93
|
-
return result
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
resultSource += `
|
|
97
|
-
global.currentInject = {
|
|
93
|
+
resultSource += `global.currentInject = {
|
|
98
94
|
moduleId: ${JSON.stringify(moduleId)}
|
|
99
95
|
};\n`
|
|
100
96
|
|
|
101
|
-
const rawCode = compiler.genNode(
|
|
97
|
+
const rawCode = compiler.genNode(root)
|
|
102
98
|
if (rawCode) {
|
|
103
99
|
try {
|
|
104
100
|
const ignoreMap = Object.assign({
|
|
@@ -116,8 +112,7 @@ global.currentInject = {
|
|
|
116
112
|
renderReduce: optimizeRenderLevel === 1,
|
|
117
113
|
ignoreMap
|
|
118
114
|
})
|
|
119
|
-
resultSource += `
|
|
120
|
-
global.currentInject.render = function (_i, _c, _r, _sc) {
|
|
115
|
+
resultSource += `global.currentInject.render = function (_i, _c, _r, _sc) {
|
|
121
116
|
${bindResult.code}
|
|
122
117
|
_r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
123
118
|
};\n`
|
|
@@ -125,10 +120,9 @@ _r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
|
125
120
|
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
|
126
121
|
}
|
|
127
122
|
} catch (e) {
|
|
128
|
-
error(`
|
|
129
|
-
Invalid render function generated by the template, please check!\n
|
|
123
|
+
error(`Invalid render function generated by the template, please check!
|
|
130
124
|
Template result:
|
|
131
|
-
${result}
|
|
125
|
+
${result}
|
|
132
126
|
Error code:
|
|
133
127
|
${rawCode}
|
|
134
128
|
Error Detail:
|
|
@@ -138,21 +132,15 @@ ${e.stack}`)
|
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
if (meta.computed) {
|
|
141
|
-
resultSource += bindThis.transform(`
|
|
142
|
-
global.currentInject.injectComputed = {
|
|
143
|
-
${meta.computed.join(',')}
|
|
144
|
-
};`).code + '\n'
|
|
135
|
+
resultSource += bindThis.transform(`global.currentInject.injectComputed = {${meta.computed.join(',')}};`).code + '\n'
|
|
145
136
|
}
|
|
146
137
|
|
|
147
138
|
if (meta.refs) {
|
|
148
|
-
resultSource += `
|
|
149
|
-
global.currentInject.getRefsData = function () {
|
|
150
|
-
return ${JSON.stringify(meta.refs)};
|
|
151
|
-
};\n`
|
|
139
|
+
resultSource += `global.currentInject.getRefsData = function () {return ${JSON.stringify(meta.refs)};};\n`
|
|
152
140
|
}
|
|
153
141
|
|
|
154
142
|
if (meta.options) {
|
|
155
|
-
resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)}
|
|
143
|
+
resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};\n`
|
|
156
144
|
}
|
|
157
145
|
|
|
158
146
|
this.emitFile(resourcePath, '', undefined, {
|
package/lib/utils/env.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function isReact (mode) {
|
|
2
|
+
return mode === 'ios' || mode === 'android'
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function isWeb (mode) {
|
|
6
|
+
return mode === 'web'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isMiniProgram (mode) {
|
|
10
|
+
return !isWeb(mode) && !isReact(mode)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
isWeb,
|
|
15
|
+
isReact,
|
|
16
|
+
isMiniProgram
|
|
17
|
+
}
|
package/lib/utils/make-map.js
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = function makeMap (str, expectsLowerCase) {
|
|
|
6
6
|
const map = Object.create(null)
|
|
7
7
|
const list = str.split(',')
|
|
8
8
|
for (let i = 0; i < list.length; i++) {
|
|
9
|
-
map[list[i]] = true
|
|
9
|
+
map[list[i].trim()] = true
|
|
10
10
|
}
|
|
11
11
|
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
|
|
12
12
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const hasOwn = require('./has-own')
|
|
2
|
+
|
|
3
|
+
module.exports = function shallowStringify (obj, isTemplateExp) {
|
|
4
|
+
const arr = []
|
|
5
|
+
for (const key in obj) {
|
|
6
|
+
if (hasOwn(obj, key)) {
|
|
7
|
+
let value = obj[key]
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
value = `[${value.join(',')}]`
|
|
10
|
+
} else if (typeof value === 'object') {
|
|
11
|
+
value = shallowStringify(value, isTemplateExp)
|
|
12
|
+
}
|
|
13
|
+
arr.push(isTemplateExp ? `${key}:${value}` : `'${key}':${value}`)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return isTemplateExp ? `({${arr.join(',')}})` : `{${arr.join(',')}}`
|
|
17
|
+
}
|
package/lib/web/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const async = require('async')
|
|
2
|
+
const processJSON = require('./processJSON')
|
|
3
|
+
const processMainScript = require('./processMainScript')
|
|
4
|
+
const processTemplate = require('./processTemplate')
|
|
5
|
+
const processStyles = require('./processStyles')
|
|
6
|
+
const processScript = require('./processScript')
|
|
7
|
+
const RecordVueContentDependency = require('../dependencies/RecordVueContentDependency')
|
|
8
|
+
|
|
9
|
+
module.exports = function ({
|
|
10
|
+
parts,
|
|
11
|
+
loaderContext,
|
|
12
|
+
pagesMap,
|
|
13
|
+
componentsMap,
|
|
14
|
+
queryObj,
|
|
15
|
+
ctorType,
|
|
16
|
+
srcMode,
|
|
17
|
+
moduleId,
|
|
18
|
+
isProduction,
|
|
19
|
+
hasScoped,
|
|
20
|
+
hasComment,
|
|
21
|
+
isNative,
|
|
22
|
+
usingComponents,
|
|
23
|
+
componentGenerics,
|
|
24
|
+
autoScope,
|
|
25
|
+
callback
|
|
26
|
+
}) {
|
|
27
|
+
const mpx = loaderContext.getMpx()
|
|
28
|
+
if (ctorType === 'app' && !queryObj.isApp) {
|
|
29
|
+
return async.waterfall([
|
|
30
|
+
(callback) => {
|
|
31
|
+
processJSON(parts.json, {
|
|
32
|
+
loaderContext,
|
|
33
|
+
pagesMap,
|
|
34
|
+
componentsMap
|
|
35
|
+
}, callback)
|
|
36
|
+
},
|
|
37
|
+
(jsonRes, callback) => {
|
|
38
|
+
processMainScript(parts.script, {
|
|
39
|
+
loaderContext,
|
|
40
|
+
ctorType,
|
|
41
|
+
srcMode,
|
|
42
|
+
moduleId,
|
|
43
|
+
isProduction,
|
|
44
|
+
jsonConfig: jsonRes.jsonObj,
|
|
45
|
+
outputPath: queryObj.outputPath || '',
|
|
46
|
+
localComponentsMap: jsonRes.localComponentsMap,
|
|
47
|
+
tabBar: jsonRes.jsonObj.tabBar,
|
|
48
|
+
tabBarMap: jsonRes.tabBarMap,
|
|
49
|
+
tabBarStr: jsonRes.tabBarStr,
|
|
50
|
+
localPagesMap: jsonRes.localPagesMap
|
|
51
|
+
}, callback)
|
|
52
|
+
}
|
|
53
|
+
], (err, scriptRes) => {
|
|
54
|
+
if (err) return callback(err)
|
|
55
|
+
loaderContext.loaderIndex = -1
|
|
56
|
+
return callback(null, scriptRes.output)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
// 通过RecordVueContentDependency和vueContentCache确保子request不再重复生成vueContent
|
|
60
|
+
const cacheContent = mpx.vueContentCache.get(loaderContext.resourcePath)
|
|
61
|
+
if (cacheContent) return callback(null, cacheContent)
|
|
62
|
+
let output = ''
|
|
63
|
+
return async.waterfall([
|
|
64
|
+
(callback) => {
|
|
65
|
+
async.parallel([
|
|
66
|
+
(callback) => {
|
|
67
|
+
processTemplate(parts.template, {
|
|
68
|
+
loaderContext,
|
|
69
|
+
hasScoped,
|
|
70
|
+
hasComment,
|
|
71
|
+
isNative,
|
|
72
|
+
srcMode,
|
|
73
|
+
moduleId,
|
|
74
|
+
ctorType,
|
|
75
|
+
usingComponents,
|
|
76
|
+
componentGenerics
|
|
77
|
+
}, callback)
|
|
78
|
+
},
|
|
79
|
+
(callback) => {
|
|
80
|
+
processStyles(parts.styles, {
|
|
81
|
+
ctorType,
|
|
82
|
+
autoScope,
|
|
83
|
+
moduleId
|
|
84
|
+
}, callback)
|
|
85
|
+
},
|
|
86
|
+
(callback) => {
|
|
87
|
+
processJSON(parts.json, {
|
|
88
|
+
loaderContext,
|
|
89
|
+
pagesMap,
|
|
90
|
+
componentsMap
|
|
91
|
+
}, callback)
|
|
92
|
+
}
|
|
93
|
+
], (err, res) => {
|
|
94
|
+
callback(err, res)
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
([templateRes, stylesRes, jsonRes], callback) => {
|
|
98
|
+
output += templateRes.output
|
|
99
|
+
output += stylesRes.output
|
|
100
|
+
output += jsonRes.output
|
|
101
|
+
processScript(parts.script, {
|
|
102
|
+
loaderContext,
|
|
103
|
+
ctorType,
|
|
104
|
+
srcMode,
|
|
105
|
+
moduleId,
|
|
106
|
+
isProduction,
|
|
107
|
+
componentGenerics,
|
|
108
|
+
jsonConfig: jsonRes.jsonObj,
|
|
109
|
+
outputPath: queryObj.outputPath || '',
|
|
110
|
+
builtInComponentsMap: templateRes.builtInComponentsMap,
|
|
111
|
+
genericsInfo: templateRes.genericsInfo,
|
|
112
|
+
wxsModuleMap: templateRes.wxsModuleMap,
|
|
113
|
+
localComponentsMap: jsonRes.localComponentsMap
|
|
114
|
+
}, callback)
|
|
115
|
+
}
|
|
116
|
+
], (err, scriptRes) => {
|
|
117
|
+
if (err) return callback(err)
|
|
118
|
+
output += scriptRes.output
|
|
119
|
+
loaderContext._module.addPresentationalDependency(new RecordVueContentDependency(loaderContext.resourcePath, output))
|
|
120
|
+
callback(null, output)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// 该文件下的字符串语句需要使用 es5 语法
|
|
2
2
|
const addQuery = require('../utils/add-query')
|
|
3
3
|
const normalize = require('../utils/normalize')
|
|
4
|
+
const shallowStringify = require('../utils/shallow-stringify')
|
|
4
5
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
5
6
|
const eventPath = normalize.lib('runtime/components/web/event')
|
|
6
7
|
const {
|
|
7
8
|
buildComponentsMap,
|
|
8
9
|
buildPagesMap,
|
|
9
10
|
buildGlobalParams,
|
|
10
|
-
shallowStringify,
|
|
11
11
|
stringifyRequest,
|
|
12
12
|
buildI18n
|
|
13
13
|
} = require('./script-helper')
|
|
@@ -23,8 +23,7 @@ module.exports = function (script, {
|
|
|
23
23
|
tabBar,
|
|
24
24
|
tabBarMap,
|
|
25
25
|
tabBarStr,
|
|
26
|
-
localPagesMap
|
|
27
|
-
resource
|
|
26
|
+
localPagesMap
|
|
28
27
|
}, callback) {
|
|
29
28
|
const { i18n, webConfig, hasUnoCSS } = loaderContext.getMpx()
|
|
30
29
|
const { pagesMap, firstPage, globalTabBar } = buildPagesMap({
|
|
@@ -68,7 +67,7 @@ module.exports = function (script, {
|
|
|
68
67
|
|
|
69
68
|
output += `\n require(${stringifyRequest(loaderContext, eventPath)})\n`
|
|
70
69
|
|
|
71
|
-
output += `\n var App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`
|
|
70
|
+
output += `\n var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
|
|
72
71
|
|
|
73
72
|
output += `
|
|
74
73
|
export default processAppOption({
|
package/lib/web/processScript.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const normalize = require('../utils/normalize')
|
|
4
|
+
const shallowStringify = require('../utils/shallow-stringify')
|
|
4
5
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
5
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
buildComponentsMap,
|
|
8
|
+
getRequireScript,
|
|
9
|
+
buildGlobalParams,
|
|
10
|
+
stringifyRequest
|
|
11
|
+
} = require('./script-helper')
|
|
6
12
|
|
|
7
13
|
module.exports = function (script, {
|
|
8
14
|
loaderContext,
|
|
@@ -20,8 +26,6 @@ module.exports = function (script, {
|
|
|
20
26
|
}, callback) {
|
|
21
27
|
const { projectRoot, appInfo } = loaderContext.getMpx()
|
|
22
28
|
|
|
23
|
-
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
24
|
-
|
|
25
29
|
let output = '/* script */\n'
|
|
26
30
|
|
|
27
31
|
let scriptSrcMode = srcMode
|
|
@@ -40,7 +44,7 @@ module.exports = function (script, {
|
|
|
40
44
|
return attrs
|
|
41
45
|
},
|
|
42
46
|
content (script) {
|
|
43
|
-
let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
|
|
47
|
+
let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
|
|
44
48
|
let hasApp = true
|
|
45
49
|
if (!appInfo.name) {
|
|
46
50
|
hasApp = false
|
|
@@ -50,7 +54,7 @@ module.exports = function (script, {
|
|
|
50
54
|
if (wxsModuleMap) {
|
|
51
55
|
Object.keys(wxsModuleMap).forEach((module) => {
|
|
52
56
|
const src = loaderUtils.urlToRequest(wxsModuleMap[module], projectRoot)
|
|
53
|
-
const expression = `require(${stringifyRequest(src)})`
|
|
57
|
+
const expression = `require(${stringifyRequest(loaderContext, src)})`
|
|
54
58
|
content += ` wxsModules.${module} = ${expression}\n`
|
|
55
59
|
})
|
|
56
60
|
}
|
|
@@ -59,23 +59,23 @@ module.exports = function (template, {
|
|
|
59
59
|
}
|
|
60
60
|
if (template.content) {
|
|
61
61
|
const templateSrcMode = template.mode || srcMode
|
|
62
|
-
|
|
62
|
+
const warn = (msg) => {
|
|
63
|
+
loaderContext.emitWarning(
|
|
64
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
const error = (msg) => {
|
|
68
|
+
loaderContext.emitError(
|
|
69
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
70
|
+
)
|
|
71
|
+
}
|
|
63
72
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
64
|
-
warn
|
|
65
|
-
|
|
66
|
-
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
67
|
-
)
|
|
68
|
-
},
|
|
69
|
-
error: (msg) => {
|
|
70
|
-
loaderContext.emitError(
|
|
71
|
-
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
72
|
-
)
|
|
73
|
-
},
|
|
73
|
+
warn,
|
|
74
|
+
error,
|
|
74
75
|
usingComponents,
|
|
75
76
|
hasComment,
|
|
76
77
|
isNative,
|
|
77
|
-
|
|
78
|
-
isPage: ctorType === 'page',
|
|
78
|
+
ctorType,
|
|
79
79
|
mode,
|
|
80
80
|
srcMode: templateSrcMode,
|
|
81
81
|
defs,
|
|
@@ -114,7 +114,7 @@ module.exports = function (template, {
|
|
|
114
114
|
return templateCompiler.serialize(root)
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
|
-
output += '\n
|
|
117
|
+
output += '\n'
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
callback(null, {
|
package/lib/web/script-helper.js
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
const hasOwn = require('../utils/has-own')
|
|
2
1
|
const loaderUtils = require('loader-utils')
|
|
3
2
|
const normalize = require('../utils/normalize')
|
|
4
3
|
const createHelpers = require('../helpers')
|
|
5
4
|
const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
|
|
6
5
|
const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
|
|
7
6
|
const addQuery = require('../utils/add-query')
|
|
7
|
+
const parseRequest = require('../utils/parse-request')
|
|
8
|
+
const shallowStringify = require('../utils/shallow-stringify')
|
|
8
9
|
|
|
9
10
|
function stringifyRequest (loaderContext, request) {
|
|
10
11
|
return loaderUtils.stringifyRequest(loaderContext, request)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
function shallowStringify (obj) {
|
|
14
|
-
const arr = []
|
|
15
|
-
for (const key in obj) {
|
|
16
|
-
if (hasOwn(obj, key)) {
|
|
17
|
-
let value = obj[key]
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
value = `[${value.join(',')}]`
|
|
20
|
-
}
|
|
21
|
-
arr.push(`'${key}':${value}`)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return `{${arr.join(',')}}`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
14
|
function getAsyncChunkName (chunkName) {
|
|
28
15
|
if (chunkName && typeof chunkName !== 'boolean') {
|
|
29
16
|
return `/* webpackChunkName: "${chunkName}" */`
|
|
@@ -128,10 +115,17 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
|
|
|
128
115
|
}
|
|
129
116
|
}
|
|
130
117
|
|
|
131
|
-
function getRequireScript ({
|
|
118
|
+
function getRequireScript ({ script, ctorType, loaderContext }) {
|
|
132
119
|
let content = ' /** script content **/\n'
|
|
133
|
-
const extraOptions = { ctorType, lang: script.lang || 'js' }
|
|
134
120
|
const { getRequire } = createHelpers(loaderContext)
|
|
121
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
122
|
+
const extraOptions = {
|
|
123
|
+
...script.src
|
|
124
|
+
? { ...queryObj, resourcePath }
|
|
125
|
+
: null,
|
|
126
|
+
ctorType,
|
|
127
|
+
lang: script.lang || 'js'
|
|
128
|
+
}
|
|
135
129
|
content += ` ${getRequire('script', script, extraOptions)}\n`
|
|
136
130
|
return content
|
|
137
131
|
}
|
|
@@ -217,8 +211,6 @@ module.exports = {
|
|
|
217
211
|
buildComponentsMap,
|
|
218
212
|
getRequireScript,
|
|
219
213
|
buildGlobalParams,
|
|
220
|
-
shallowStringify,
|
|
221
|
-
getAsyncChunkName,
|
|
222
214
|
stringifyRequest,
|
|
223
215
|
buildI18n
|
|
224
216
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.19-react.0",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -78,10 +78,14 @@
|
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/babel-traverse": "^6.25.4",
|
|
81
|
-
"@types/babel-types": "^7.0.4"
|
|
81
|
+
"@types/babel-types": "^7.0.4",
|
|
82
|
+
"@types/react": "^18.2.79",
|
|
83
|
+
"react": "^18.2.0",
|
|
84
|
+
"react-native": "^0.74.0",
|
|
85
|
+
"react-native-svg": "^15.2.0"
|
|
82
86
|
},
|
|
83
87
|
"engines": {
|
|
84
88
|
"node": ">=14.14.0"
|
|
85
89
|
},
|
|
86
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "a09ab1b994eaf20b1772491709580fe75499e688"
|
|
87
91
|
}
|