@mpxjs/webpack-plugin 2.9.39 → 2.9.41-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 +63 -97
- package/lib/dependencies/{RecordVueContentDependency.js → RecordLoaderContentDependency.js} +5 -5
- package/lib/dependencies/ResolveDependency.js +2 -2
- package/lib/helpers.js +5 -1
- package/lib/index.js +26 -21
- package/lib/loader.js +43 -97
- package/lib/native-loader.js +0 -1
- package/lib/platform/index.js +3 -0
- package/lib/platform/style/wx/index.js +414 -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 +41 -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 +104 -0
- package/lib/react/processJSON.js +361 -0
- package/lib/react/processMainScript.js +21 -0
- package/lib/react/processScript.js +70 -0
- package/lib/react/processStyles.js +69 -0
- package/lib/react/processTemplate.js +153 -0
- package/lib/react/script-helper.js +133 -0
- package/lib/react/style-helper.js +91 -0
- package/lib/resolver/PackageEntryPlugin.js +1 -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 +398 -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/useNodesRef.ts +39 -0
- package/lib/runtime/components/react/utils.ts +92 -0
- package/lib/runtime/optionProcessorReact.d.ts +9 -0
- package/lib/runtime/optionProcessorReact.js +21 -0
- package/lib/runtime/stringify.wxs +3 -8
- package/lib/style-compiler/index.js +2 -1
- package/lib/template-compiler/compiler.js +293 -38
- package/lib/template-compiler/gen-node-react.js +95 -0
- package/lib/template-compiler/index.js +15 -24
- package/lib/utils/env.js +17 -0
- package/lib/utils/make-map.js +1 -1
- package/lib/utils/shallow-stringify.js +12 -12
- package/lib/web/index.js +123 -0
- package/lib/web/processJSON.js +3 -3
- package/lib/web/processMainScript.js +25 -23
- package/lib/web/processScript.js +12 -16
- package/lib/web/processTemplate.js +13 -12
- package/lib/web/script-helper.js +14 -22
- package/package.json +4 -3
|
@@ -12,7 +12,7 @@ module.exports = function (raw) {
|
|
|
12
12
|
this.cacheable()
|
|
13
13
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
14
14
|
const mpx = this.getMpx()
|
|
15
|
-
const
|
|
15
|
+
const projectRoot = mpx.projectRoot
|
|
16
16
|
const mode = mpx.mode
|
|
17
17
|
const env = mpx.env
|
|
18
18
|
const defs = mpx.defs
|
|
@@ -40,6 +40,7 @@ module.exports = function (raw) {
|
|
|
40
40
|
break
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
|
|
43
44
|
const warn = (msg) => {
|
|
44
45
|
this.emitWarning(
|
|
45
46
|
new Error('[template compiler][' + this.resource + ']: ' + msg)
|
|
@@ -52,7 +53,7 @@ module.exports = function (raw) {
|
|
|
52
53
|
)
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
const { root
|
|
56
|
+
const { root, meta } = compiler.parse(raw, {
|
|
56
57
|
warn,
|
|
57
58
|
error,
|
|
58
59
|
runtimeCompile,
|
|
@@ -84,8 +85,7 @@ module.exports = function (raw) {
|
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
let result = runtimeCompile ? '' : compiler.serialize(
|
|
88
|
-
|
|
88
|
+
let result = runtimeCompile ? '' : compiler.serialize(root)
|
|
89
89
|
if (isNative) {
|
|
90
90
|
return result
|
|
91
91
|
}
|
|
@@ -93,20 +93,19 @@ module.exports = function (raw) {
|
|
|
93
93
|
let resultSource = ''
|
|
94
94
|
|
|
95
95
|
for (const module in meta.wxsModuleMap) {
|
|
96
|
-
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module],
|
|
96
|
+
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], projectRoot)
|
|
97
97
|
resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
resultSource += `
|
|
101
|
-
global.currentInject = {
|
|
100
|
+
resultSource += `global.currentInject = {
|
|
102
101
|
moduleId: ${JSON.stringify(moduleId)}
|
|
103
102
|
};\n`
|
|
104
103
|
|
|
105
|
-
if (runtimeCompile
|
|
104
|
+
if (runtimeCompile) {
|
|
106
105
|
resultSource += 'global.currentInject.dynamic = true;\n'
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
const rawCode = runtimeCompile ? '' : compiler.genNode(
|
|
108
|
+
const rawCode = runtimeCompile ? '' : compiler.genNode(root)
|
|
110
109
|
if (rawCode) {
|
|
111
110
|
try {
|
|
112
111
|
const ignoreMap = Object.assign({
|
|
@@ -124,8 +123,7 @@ global.currentInject = {
|
|
|
124
123
|
renderReduce: optimizeRenderLevel === 1,
|
|
125
124
|
ignoreMap
|
|
126
125
|
})
|
|
127
|
-
resultSource += `
|
|
128
|
-
global.currentInject.render = function (_i, _c, _r, _sc) {
|
|
126
|
+
resultSource += `global.currentInject.render = function (_i, _c, _r, _sc) {
|
|
129
127
|
${bindResult.code}
|
|
130
128
|
_r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
131
129
|
};\n`
|
|
@@ -133,10 +131,9 @@ _r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
|
133
131
|
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
|
134
132
|
}
|
|
135
133
|
} catch (e) {
|
|
136
|
-
error(`
|
|
137
|
-
Invalid render function generated by the template, please check!\n
|
|
134
|
+
error(`Invalid render function generated by the template, please check!
|
|
138
135
|
Template result:
|
|
139
|
-
${result}
|
|
136
|
+
${result}
|
|
140
137
|
Error code:
|
|
141
138
|
${rawCode}
|
|
142
139
|
Error Detail:
|
|
@@ -146,21 +143,15 @@ ${e.stack}`)
|
|
|
146
143
|
}
|
|
147
144
|
|
|
148
145
|
if (meta.computed) {
|
|
149
|
-
resultSource += bindThis.transform(`
|
|
150
|
-
global.currentInject.injectComputed = {
|
|
151
|
-
${meta.computed.join(',')}
|
|
152
|
-
};`).code + '\n'
|
|
146
|
+
resultSource += bindThis.transform(`global.currentInject.injectComputed = {${meta.computed.join(',')}};`).code + '\n'
|
|
153
147
|
}
|
|
154
148
|
|
|
155
149
|
if (meta.refs) {
|
|
156
|
-
resultSource += `
|
|
157
|
-
global.currentInject.getRefsData = function () {
|
|
158
|
-
return ${JSON.stringify(meta.refs)};
|
|
159
|
-
};\n`
|
|
150
|
+
resultSource += `global.currentInject.getRefsData = function () { return ${JSON.stringify(meta.refs)}; };\n`
|
|
160
151
|
}
|
|
161
152
|
|
|
162
153
|
if (meta.options) {
|
|
163
|
-
resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)}
|
|
154
|
+
resultSource += `global.currentInject.injectOptions = ${JSON.stringify(meta.options)};\n`
|
|
164
155
|
}
|
|
165
156
|
|
|
166
157
|
this.emitFile(resourcePath, '', undefined, {
|
|
@@ -180,7 +171,7 @@ global.currentInject.getRefsData = function () {
|
|
|
180
171
|
this.emitFile(MPX_DISABLE_EXTRACTOR_CACHE, '', undefined, { skipEmit: true })
|
|
181
172
|
|
|
182
173
|
const templateInfo = {
|
|
183
|
-
templateAst: stringify(
|
|
174
|
+
templateAst: stringify(root),
|
|
184
175
|
...meta.runtimeInfo
|
|
185
176
|
}
|
|
186
177
|
|
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
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
const hasOwn = require('./has-own')
|
|
2
2
|
|
|
3
3
|
module.exports = function shallowStringify (obj, isTemplateExp) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
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}`)
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
return isTemplateExp ? `({${arr.join(',')}})` : `{${arr.join(',')}}`
|
|
17
17
|
}
|
package/lib/web/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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 RecordLoaderContentDependency = require('../dependencies/RecordLoaderContentDependency')
|
|
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
|
+
if (ctorType === 'app' && !queryObj.isApp) {
|
|
28
|
+
return async.waterfall([
|
|
29
|
+
(callback) => {
|
|
30
|
+
processJSON(parts.json, {
|
|
31
|
+
loaderContext,
|
|
32
|
+
ctorType,
|
|
33
|
+
pagesMap,
|
|
34
|
+
componentsMap
|
|
35
|
+
}, callback)
|
|
36
|
+
},
|
|
37
|
+
(jsonRes, callback) => {
|
|
38
|
+
processMainScript(parts.script, {
|
|
39
|
+
loaderContext,
|
|
40
|
+
srcMode,
|
|
41
|
+
moduleId,
|
|
42
|
+
isProduction,
|
|
43
|
+
jsonConfig: jsonRes.jsonObj,
|
|
44
|
+
outputPath: queryObj.outputPath || '',
|
|
45
|
+
localComponentsMap: jsonRes.localComponentsMap,
|
|
46
|
+
tabBar: jsonRes.jsonObj.tabBar,
|
|
47
|
+
tabBarMap: jsonRes.tabBarMap,
|
|
48
|
+
tabBarStr: jsonRes.tabBarStr,
|
|
49
|
+
localPagesMap: jsonRes.localPagesMap
|
|
50
|
+
}, callback)
|
|
51
|
+
}
|
|
52
|
+
], (err, scriptRes) => {
|
|
53
|
+
if (err) return callback(err)
|
|
54
|
+
loaderContext.loaderIndex = -1
|
|
55
|
+
return callback(null, scriptRes.output)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
const mpx = loaderContext.getMpx()
|
|
59
|
+
// 通过RecordLoaderContentDependency和loaderContentCache确保子request不再重复生成loaderContent
|
|
60
|
+
const cacheContent = mpx.loaderContentCache.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
|
+
ctorType,
|
|
90
|
+
pagesMap,
|
|
91
|
+
componentsMap
|
|
92
|
+
}, callback)
|
|
93
|
+
}
|
|
94
|
+
], (err, res) => {
|
|
95
|
+
callback(err, res)
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
([templateRes, stylesRes, jsonRes], callback) => {
|
|
99
|
+
output += templateRes.output
|
|
100
|
+
output += stylesRes.output
|
|
101
|
+
output += jsonRes.output
|
|
102
|
+
processScript(parts.script, {
|
|
103
|
+
loaderContext,
|
|
104
|
+
ctorType,
|
|
105
|
+
srcMode,
|
|
106
|
+
moduleId,
|
|
107
|
+
isProduction,
|
|
108
|
+
componentGenerics,
|
|
109
|
+
jsonConfig: jsonRes.jsonObj,
|
|
110
|
+
outputPath: queryObj.outputPath || '',
|
|
111
|
+
builtInComponentsMap: templateRes.builtInComponentsMap,
|
|
112
|
+
genericsInfo: templateRes.genericsInfo,
|
|
113
|
+
wxsModuleMap: templateRes.wxsModuleMap,
|
|
114
|
+
localComponentsMap: jsonRes.localComponentsMap
|
|
115
|
+
}, callback)
|
|
116
|
+
}
|
|
117
|
+
], (err, scriptRes) => {
|
|
118
|
+
if (err) return callback(err)
|
|
119
|
+
output += scriptRes.output
|
|
120
|
+
loaderContext._module.addPresentationalDependency(new RecordLoaderContentDependency(loaderContext.resourcePath, output))
|
|
121
|
+
callback(null, output)
|
|
122
|
+
})
|
|
123
|
+
}
|
package/lib/web/processJSON.js
CHANGED
|
@@ -16,6 +16,7 @@ const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalCo
|
|
|
16
16
|
|
|
17
17
|
module.exports = function (json, {
|
|
18
18
|
loaderContext,
|
|
19
|
+
ctorType,
|
|
19
20
|
pagesMap,
|
|
20
21
|
componentsMap
|
|
21
22
|
}, rawCallback) {
|
|
@@ -79,8 +80,7 @@ module.exports = function (json, {
|
|
|
79
80
|
})
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
const
|
|
83
|
-
const isApp = !(pagesMap[resourcePath] || componentsMap[resourcePath])
|
|
83
|
+
const isApp = ctorType === 'app'
|
|
84
84
|
|
|
85
85
|
if (!json) {
|
|
86
86
|
return callback()
|
|
@@ -103,7 +103,7 @@ module.exports = function (json, {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (!isApp) {
|
|
106
|
-
rulesRunnerOptions.mainKey =
|
|
106
|
+
rulesRunnerOptions.mainKey = ctorType
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const rulesRunner = getRulesRunner(rulesRunnerOptions)
|
|
@@ -1,20 +1,19 @@
|
|
|
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
|
|
|
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')
|
|
14
14
|
|
|
15
15
|
module.exports = function (script, {
|
|
16
16
|
loaderContext,
|
|
17
|
-
ctorType,
|
|
18
17
|
srcMode,
|
|
19
18
|
moduleId,
|
|
20
19
|
isProduction,
|
|
@@ -23,8 +22,7 @@ module.exports = function (script, {
|
|
|
23
22
|
tabBar,
|
|
24
23
|
tabBarMap,
|
|
25
24
|
tabBarStr,
|
|
26
|
-
localPagesMap
|
|
27
|
-
resource
|
|
25
|
+
localPagesMap
|
|
28
26
|
}, callback) {
|
|
29
27
|
const { i18n, webConfig, hasUnoCSS } = loaderContext.getMpx()
|
|
30
28
|
const { pagesMap, firstPage, globalTabBar } = buildPagesMap({
|
|
@@ -36,20 +34,24 @@ module.exports = function (script, {
|
|
|
36
34
|
jsonConfig
|
|
37
35
|
})
|
|
38
36
|
|
|
39
|
-
const componentsMap = buildComponentsMap({
|
|
37
|
+
const componentsMap = buildComponentsMap({
|
|
38
|
+
localComponentsMap,
|
|
39
|
+
loaderContext,
|
|
40
|
+
jsonConfig
|
|
41
|
+
})
|
|
40
42
|
|
|
41
43
|
const scriptSrcMode = script ? script.mode || srcMode : srcMode
|
|
42
44
|
|
|
43
|
-
let output = '
|
|
45
|
+
let output = 'import \'@mpxjs/webpack-plugin/lib/runtime/base.styl\'\n'
|
|
44
46
|
// hasUnoCSS由@mpxjs/unocss-plugin注入
|
|
45
47
|
if (hasUnoCSS) {
|
|
46
|
-
output += '
|
|
48
|
+
output += 'import \'uno.css\'\n'
|
|
47
49
|
}
|
|
48
|
-
output += `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
output += `import Vue from 'vue'
|
|
51
|
+
import VueRouter from 'vue-router'
|
|
52
|
+
import Mpx from '@mpxjs/core'
|
|
53
|
+
import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
54
|
+
Vue.use(VueRouter)\n`
|
|
53
55
|
|
|
54
56
|
if (i18n) {
|
|
55
57
|
output += buildI18n({ i18n, loaderContext })
|
|
@@ -66,19 +68,19 @@ module.exports = function (script, {
|
|
|
66
68
|
globalTabBar
|
|
67
69
|
})
|
|
68
70
|
|
|
69
|
-
output +=
|
|
71
|
+
output += `var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
|
|
70
72
|
|
|
71
73
|
output += `
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
export default processAppOption({
|
|
75
|
+
App: App,
|
|
76
|
+
tabBarMap: ${JSON.stringify(tabBarMap)},
|
|
77
|
+
firstPage: ${JSON.stringify(firstPage)},
|
|
78
|
+
pagesMap: ${shallowStringify(pagesMap)},
|
|
79
|
+
componentsMap: ${shallowStringify(componentsMap)},
|
|
80
|
+
Vue: Vue,
|
|
81
|
+
VueRouter: VueRouter,
|
|
82
|
+
el: ${JSON.stringify(webConfig.el || '#app')}
|
|
83
|
+
})\n`
|
|
82
84
|
|
|
83
85
|
callback(null, {
|
|
84
86
|
output
|
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, webConfig } = 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,17 +44,17 @@ 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
|
|
47
51
|
}
|
|
48
52
|
// 注入wxs模块
|
|
49
|
-
content += '
|
|
53
|
+
content += ' var wxsModules = {}\n'
|
|
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
|
}
|
|
@@ -61,16 +65,8 @@ module.exports = function (script, {
|
|
|
61
65
|
// 获取pageConfig
|
|
62
66
|
const pageConfig = {}
|
|
63
67
|
if (ctorType === 'page') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
'style',
|
|
67
|
-
'singlePage'
|
|
68
|
-
])
|
|
69
|
-
Object.keys(jsonConfig)
|
|
70
|
-
.filter(key => !uselessOptions.has(key))
|
|
71
|
-
.forEach(key => {
|
|
72
|
-
pageConfig[key] = jsonConfig[key]
|
|
73
|
-
})
|
|
68
|
+
Object.assign(pageConfig, jsonConfig)
|
|
69
|
+
delete pageConfig.usingComponents
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
|
|
@@ -60,18 +60,19 @@ module.exports = function (template, {
|
|
|
60
60
|
}
|
|
61
61
|
if (template.content) {
|
|
62
62
|
const templateSrcMode = template.mode || srcMode
|
|
63
|
-
|
|
63
|
+
const warn = (msg) => {
|
|
64
|
+
loaderContext.emitWarning(
|
|
65
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
const error = (msg) => {
|
|
69
|
+
loaderContext.emitError(
|
|
70
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
71
|
+
)
|
|
72
|
+
}
|
|
64
73
|
const { root, meta } = templateCompiler.parse(template.content, {
|
|
65
|
-
warn
|
|
66
|
-
|
|
67
|
-
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
68
|
-
)
|
|
69
|
-
},
|
|
70
|
-
error: (msg) => {
|
|
71
|
-
loaderContext.emitError(
|
|
72
|
-
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
73
|
-
)
|
|
74
|
-
},
|
|
74
|
+
warn,
|
|
75
|
+
error,
|
|
75
76
|
usingComponents,
|
|
76
77
|
hasComment,
|
|
77
78
|
isNative,
|
|
@@ -115,7 +116,7 @@ module.exports = function (template, {
|
|
|
115
116
|
return templateCompiler.serialize(root)
|
|
116
117
|
}
|
|
117
118
|
})
|
|
118
|
-
output += '\n
|
|
119
|
+
output += '\n'
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
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
|
}
|
|
@@ -150,15 +144,15 @@ function buildGlobalParams ({
|
|
|
150
144
|
let content = ''
|
|
151
145
|
if (isMain) {
|
|
152
146
|
content += `
|
|
153
|
-
global.getApp = function(){}
|
|
147
|
+
global.getApp = function () {}
|
|
154
148
|
global.getCurrentPages = function () {
|
|
155
149
|
if (!(typeof window !== 'undefined')) {
|
|
156
150
|
console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
|
|
157
151
|
}
|
|
158
152
|
var router = global.__mpxRouter
|
|
159
|
-
if(!router) return []
|
|
153
|
+
if (!router) return []
|
|
160
154
|
// @ts-ignore
|
|
161
|
-
return (router.lastStack || router.stack).map(function(item){
|
|
155
|
+
return (router.lastStack || router.stack).map(function (item) {
|
|
162
156
|
var page
|
|
163
157
|
var vnode = item.vnode
|
|
164
158
|
if (vnode && vnode.componentInstance) {
|
|
@@ -223,8 +217,6 @@ module.exports = {
|
|
|
223
217
|
buildComponentsMap,
|
|
224
218
|
getRequireScript,
|
|
225
219
|
buildGlobalParams,
|
|
226
|
-
shallowStringify,
|
|
227
|
-
getAsyncChunkName,
|
|
228
220
|
stringifyRequest,
|
|
229
221
|
buildI18n
|
|
230
222
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.41-react.0",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -79,10 +79,11 @@
|
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/babel-traverse": "^6.25.4",
|
|
82
|
-
"@types/babel-types": "^7.0.4"
|
|
82
|
+
"@types/babel-types": "^7.0.4",
|
|
83
|
+
"@types/react": "^18.2.79"
|
|
83
84
|
},
|
|
84
85
|
"engines": {
|
|
85
86
|
"node": ">=14.14.0"
|
|
86
87
|
},
|
|
87
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "1c9ae7527a257fad98f5536114e63415cea54271"
|
|
88
89
|
}
|