@mpxjs/webpack-plugin 2.8.40-test → 2.8.40-test.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dependencies/DynamicEntryDependency.js +10 -16
- package/lib/index.js +87 -60
- package/lib/json-compiler/helper.js +8 -5
- package/lib/json-compiler/index.js +2 -2
- package/lib/loader.js +28 -27
- package/lib/parser.js +0 -1
- package/lib/platform/index.js +15 -4
- package/lib/platform/json/wx/index.js +3 -5
- package/lib/platform/run-rules.js +1 -2
- package/lib/platform/template/normalize-component-rules.js +41 -42
- package/lib/platform/template/wx/component-config/component.js +1 -2
- package/lib/platform/template/wx/component-config/fix-component-name.js +21 -0
- package/lib/platform/template/wx/component-config/index.js +4 -4
- package/lib/platform/template/wx/index.js +21 -16
- package/lib/runtime/base.styl +9 -1
- package/lib/runtime/components/web/getInnerListeners.js +1 -2
- package/lib/runtime/components/web/mpx-image.vue +13 -10
- package/lib/runtime/components/web/mpx-movable-view.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +10 -2
- package/lib/runtime/components/web/mpx-picker.vue +9 -1
- package/lib/runtime/components/web/mpx-swiper.vue +2 -2
- package/lib/runtime/optionProcessor.js +321 -264
- package/lib/runtime/stringify.wxs +44 -8
- package/lib/style-compiler/index.js +1 -2
- package/lib/template-compiler/compiler.js +74 -56
- package/lib/utils/check-core-version-match.js +18 -14
- package/lib/web/processJSON.js +4 -3
- package/lib/web/processMainScript.js +84 -0
- package/lib/web/processScript.js +21 -204
- package/lib/web/processTemplate.js +4 -1
- package/lib/web/script-helper.js +202 -0
- package/package.json +5 -4
- package/lib/platform/template/wx/component-config/fix-html-tag.js +0 -17
- package/lib/style-compiler/plugins/trim.js +0 -15
|
@@ -24,8 +24,9 @@ function objectKeys (obj) {
|
|
|
24
24
|
var shift = false
|
|
25
25
|
for (var i = 1; i < objStr.length - 1; i++) {
|
|
26
26
|
var item = objStr[i]
|
|
27
|
+
var lastItem = objStr[i - 1]
|
|
27
28
|
if (inKey) {
|
|
28
|
-
if (item === ':') {
|
|
29
|
+
if (item === ':' && lastItem === '"') {
|
|
29
30
|
keys.push(key.slice(1, -1))
|
|
30
31
|
key = ''
|
|
31
32
|
inKey = false
|
|
@@ -93,18 +94,53 @@ function isDef (v) {
|
|
|
93
94
|
return v !== undefined && v !== null
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
var escapeMap = {
|
|
98
|
+
'(': '_pl_',
|
|
99
|
+
')': '_pr_',
|
|
100
|
+
'[': '_bl_',
|
|
101
|
+
']': '_br_',
|
|
102
|
+
'{': '_cl_',
|
|
103
|
+
'#': '_h_',
|
|
104
|
+
'!': '_i_',
|
|
105
|
+
'/': '_s_',
|
|
106
|
+
'.': '_d_',
|
|
107
|
+
':': '_c_',
|
|
108
|
+
',': '_2c_',
|
|
109
|
+
'%': '_p_',
|
|
110
|
+
// wxs can not use '\'' as key
|
|
111
|
+
// wxs环境中'\''!=="'",此文件不能格式化,否则会导致程序错误
|
|
112
|
+
"'": '_q_',
|
|
113
|
+
// wxs can not use '"' as key
|
|
114
|
+
'"': '_dq_',
|
|
115
|
+
'+': '_a_',
|
|
116
|
+
'$': '_si_'
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var escapeReg = genRegExp('[()[\]{}#!/.:,%\'"+$]', 'g')
|
|
120
|
+
|
|
121
|
+
function mpEscape (str) {
|
|
122
|
+
return str.replace(escapeReg, function (match) {
|
|
123
|
+
if (escapeMap[match]) return escapeMap[match]
|
|
124
|
+
// fix wxs can not use '}' as key
|
|
125
|
+
if (match === '}') return '_cr_'
|
|
126
|
+
// unknown escaped
|
|
127
|
+
return '_u_'
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
96
132
|
function stringifyDynamicClass (value) {
|
|
97
|
-
if (!value) return ''
|
|
98
133
|
if (isArray(value)) {
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return stringifyObject(value)
|
|
134
|
+
value = stringifyArray(value)
|
|
135
|
+
} else if (isObject(value)) {
|
|
136
|
+
value = stringifyObject(value)
|
|
103
137
|
}
|
|
138
|
+
|
|
104
139
|
if (typeof value === 'string') {
|
|
105
|
-
return value
|
|
140
|
+
return mpEscape(value)
|
|
141
|
+
} else {
|
|
142
|
+
return ''
|
|
106
143
|
}
|
|
107
|
-
return ''
|
|
108
144
|
}
|
|
109
145
|
|
|
110
146
|
function stringifyArray (value) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const postcss = require('postcss')
|
|
2
2
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
3
3
|
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
4
|
-
const trim = require('./plugins/trim')
|
|
5
4
|
const rpx = require('./plugins/rpx')
|
|
6
5
|
const vw = require('./plugins/vw')
|
|
7
6
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
@@ -30,7 +29,7 @@ module.exports = function (css, map) {
|
|
|
30
29
|
|
|
31
30
|
const inlineConfig = Object.assign({}, mpx.postcssInlineConfig, { defs })
|
|
32
31
|
loadPostcssConfig(this, inlineConfig).then(config => {
|
|
33
|
-
const plugins = [
|
|
32
|
+
const plugins = [] // init with trim plugin
|
|
34
33
|
const options = Object.assign(
|
|
35
34
|
{
|
|
36
35
|
to: this.resourcePath,
|
|
@@ -738,7 +738,7 @@ function parse (template, options) {
|
|
|
738
738
|
},
|
|
739
739
|
comment: function comment (text) {
|
|
740
740
|
if (!currentParent) genTempRoot()
|
|
741
|
-
if (options.hasComment) {
|
|
741
|
+
if (options.hasComment || /mpx_config_/.test(text)) {
|
|
742
742
|
currentParent.children.push({
|
|
743
743
|
type: 3,
|
|
744
744
|
text: text,
|
|
@@ -944,7 +944,7 @@ function processComponentIs (el, options) {
|
|
|
944
944
|
|
|
945
945
|
const is = getAndRemoveAttr(el, 'is').val
|
|
946
946
|
if (is) {
|
|
947
|
-
el.is =
|
|
947
|
+
el.is = parseMustacheWithContext(is).result
|
|
948
948
|
} else {
|
|
949
949
|
warn$1('<component> tag should have attrs[is].')
|
|
950
950
|
}
|
|
@@ -956,7 +956,7 @@ function parseFuncStr2 (str) {
|
|
|
956
956
|
const funcRE = /^([^()]+)(\((.*)\))?/
|
|
957
957
|
const match = funcRE.exec(str)
|
|
958
958
|
if (match) {
|
|
959
|
-
const funcName =
|
|
959
|
+
const funcName = parseMustacheWithContext(match[1]).result
|
|
960
960
|
const hasArgs = !!match[2]
|
|
961
961
|
let args = match[3] ? `,${match[3]}` : ''
|
|
962
962
|
const ret = /(,|^)\s*(\$event)\s*(,|$)/.exec(args)
|
|
@@ -1142,19 +1142,9 @@ function wrapMustache (val) {
|
|
|
1142
1142
|
return val && !tagRE.test(val) ? `{{${val}}}` : val
|
|
1143
1143
|
}
|
|
1144
1144
|
|
|
1145
|
-
function
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
const ret = []
|
|
1149
|
-
let lastLastIndex = 0
|
|
1150
|
-
let match
|
|
1151
|
-
while (match = tagREG.exec(raw)) {
|
|
1152
|
-
const pre = raw.substring(lastLastIndex, match.index)
|
|
1153
|
-
if (pre) {
|
|
1154
|
-
ret.push(stringify(pre))
|
|
1155
|
-
}
|
|
1156
|
-
let exp = match[1]
|
|
1157
|
-
|
|
1145
|
+
function parseMustacheWithContext (raw = '') {
|
|
1146
|
+
return parseMustache(raw, (exp) => {
|
|
1147
|
+
if (defs) {
|
|
1158
1148
|
// eval处理的话,和别的判断条件,比如运行时的判断混用情况下得不到一个结果,还是正则替换
|
|
1159
1149
|
const defKeys = Object.keys(defs)
|
|
1160
1150
|
defKeys.forEach((defKey) => {
|
|
@@ -1162,42 +1152,70 @@ function parseMustache (raw = '') {
|
|
|
1162
1152
|
const defREG = new RegExp(`\\b${defKey}\\b`, 'g')
|
|
1163
1153
|
if (defRE.test(exp)) {
|
|
1164
1154
|
exp = exp.replace(defREG, stringify(defs[defKey]))
|
|
1165
|
-
replaced = true
|
|
1166
1155
|
}
|
|
1167
1156
|
})
|
|
1157
|
+
}
|
|
1168
1158
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1181
|
-
hasI18n = true
|
|
1182
|
-
replaced = true
|
|
1183
|
-
break
|
|
1159
|
+
if (i18n) {
|
|
1160
|
+
for (const i18nFuncName of i18nFuncNames) {
|
|
1161
|
+
const funcNameRE = new RegExp(`(?<![A-Za-z0-9_$.])${i18nFuncName}\\(`)
|
|
1162
|
+
const funcNameREG = new RegExp(`(?<![A-Za-z0-9_$.])${i18nFuncName}\\(`, 'g')
|
|
1163
|
+
if (funcNameRE.test(exp)) {
|
|
1164
|
+
if (i18n.useComputed || !i18nFuncName.startsWith('\\$')) {
|
|
1165
|
+
const i18nInjectComputedKey = `_i${i18nInjectableComputed.length + 1}`
|
|
1166
|
+
i18nInjectableComputed.push(`${i18nInjectComputedKey} () {\nreturn ${exp.trim()}}`)
|
|
1167
|
+
exp = i18nInjectComputedKey
|
|
1168
|
+
} else {
|
|
1169
|
+
exp = exp.replace(funcNameREG, `${i18nModuleName}.$1(null, _l, _fl, `)
|
|
1184
1170
|
}
|
|
1171
|
+
hasI18n = true
|
|
1172
|
+
break
|
|
1185
1173
|
}
|
|
1186
1174
|
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
return exp
|
|
1178
|
+
})
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function parseMustache (raw = '', expHandler = exp => exp, strHandler = str => str) {
|
|
1182
|
+
let replaced = false
|
|
1183
|
+
if (tagRE.test(raw)) {
|
|
1184
|
+
const ret = []
|
|
1185
|
+
let lastLastIndex = 0
|
|
1186
|
+
let match
|
|
1187
|
+
while (match = tagREG.exec(raw)) {
|
|
1188
|
+
const pre = raw.substring(lastLastIndex, match.index)
|
|
1189
|
+
if (pre) {
|
|
1190
|
+
const pre2 = strHandler(pre)
|
|
1191
|
+
if (pre2 !== pre) replaced = true
|
|
1192
|
+
if (pre2) ret.push(stringify(pre2))
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
const exp = match[1].trim()
|
|
1196
|
+
if (exp) {
|
|
1197
|
+
const exp2 = expHandler(exp)
|
|
1198
|
+
if (exp2 !== exp) replaced = true
|
|
1199
|
+
if (exp2) ret.push(`(${exp2})`)
|
|
1200
|
+
}
|
|
1187
1201
|
|
|
1188
|
-
ret.push(`(${exp.trim()})`)
|
|
1189
1202
|
lastLastIndex = tagREG.lastIndex
|
|
1190
1203
|
}
|
|
1204
|
+
|
|
1191
1205
|
const post = raw.substring(lastLastIndex)
|
|
1192
1206
|
if (post) {
|
|
1193
|
-
|
|
1207
|
+
const post2 = strHandler(post)
|
|
1208
|
+
if (post2 !== post) replaced = true
|
|
1209
|
+
if (post2) ret.push(stringify(post2))
|
|
1194
1210
|
}
|
|
1211
|
+
|
|
1195
1212
|
let result
|
|
1196
1213
|
if (ret.length === 1) {
|
|
1197
1214
|
result = ret[0]
|
|
1198
1215
|
} else {
|
|
1199
1216
|
result = `(${ret.join('+')})`
|
|
1200
1217
|
}
|
|
1218
|
+
|
|
1201
1219
|
return {
|
|
1202
1220
|
result,
|
|
1203
1221
|
hasBinding: true,
|
|
@@ -1205,10 +1223,14 @@ function parseMustache (raw = '') {
|
|
|
1205
1223
|
replaced
|
|
1206
1224
|
}
|
|
1207
1225
|
}
|
|
1226
|
+
|
|
1227
|
+
const raw2 = strHandler(raw)
|
|
1228
|
+
if (raw2 !== raw) replaced = true
|
|
1229
|
+
|
|
1208
1230
|
return {
|
|
1209
|
-
result: stringify(
|
|
1231
|
+
result: stringify(raw2),
|
|
1210
1232
|
hasBinding: false,
|
|
1211
|
-
val:
|
|
1233
|
+
val: raw2,
|
|
1212
1234
|
replaced
|
|
1213
1235
|
}
|
|
1214
1236
|
}
|
|
@@ -1226,14 +1248,14 @@ function processIf (el) {
|
|
|
1226
1248
|
let val = getAndRemoveAttr(el, config[mode].directive.if).val
|
|
1227
1249
|
if (val) {
|
|
1228
1250
|
if (mode === 'swan') val = wrapMustache(val)
|
|
1229
|
-
const parsed =
|
|
1251
|
+
const parsed = parseMustacheWithContext(val)
|
|
1230
1252
|
el.if = {
|
|
1231
1253
|
raw: parsed.val,
|
|
1232
1254
|
exp: parsed.result
|
|
1233
1255
|
}
|
|
1234
1256
|
} else if (val = getAndRemoveAttr(el, config[mode].directive.elseif).val) {
|
|
1235
1257
|
if (mode === 'swan') val = wrapMustache(val)
|
|
1236
|
-
const parsed =
|
|
1258
|
+
const parsed = parseMustacheWithContext(val)
|
|
1237
1259
|
el.elseif = {
|
|
1238
1260
|
raw: parsed.val,
|
|
1239
1261
|
exp: parsed.result
|
|
@@ -1275,7 +1297,7 @@ function processFor (el) {
|
|
|
1275
1297
|
}
|
|
1276
1298
|
} else {
|
|
1277
1299
|
if (mode === 'swan') val = wrapMustache(val)
|
|
1278
|
-
const parsed =
|
|
1300
|
+
const parsed = parseMustacheWithContext(val)
|
|
1279
1301
|
el.for = {
|
|
1280
1302
|
raw: parsed.val,
|
|
1281
1303
|
exp: parsed.result
|
|
@@ -1387,14 +1409,14 @@ function processAttrs (el, options) {
|
|
|
1387
1409
|
const isTemplateData = el.tag === 'template' && attr.name === 'data'
|
|
1388
1410
|
const needWrap = isTemplateData && mode !== 'swan'
|
|
1389
1411
|
const value = needWrap ? `{${attr.value}}` : attr.value
|
|
1390
|
-
const parsed =
|
|
1412
|
+
const parsed = parseMustacheWithContext(value)
|
|
1391
1413
|
if (parsed.hasBinding) {
|
|
1392
1414
|
// 该属性判断用于提供给运行时对于计算属性作为props传递时提出警告
|
|
1393
1415
|
const isProps = isComponentNode(el, options) && !(attr.name === 'class' || attr.name === 'style')
|
|
1394
1416
|
addExp(el, parsed.result, isProps)
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1417
|
+
if (parsed.replaced) {
|
|
1418
|
+
modifyAttr(el, attr.name, needWrap ? parsed.val.slice(1, -1) : parsed.val)
|
|
1419
|
+
}
|
|
1398
1420
|
}
|
|
1399
1421
|
})
|
|
1400
1422
|
}
|
|
@@ -1526,7 +1548,7 @@ function processText (el) {
|
|
|
1526
1548
|
if (el.type !== 3 || el.isComment) {
|
|
1527
1549
|
return
|
|
1528
1550
|
}
|
|
1529
|
-
const parsed =
|
|
1551
|
+
const parsed = parseMustacheWithContext(el.text)
|
|
1530
1552
|
if (parsed.hasBinding) {
|
|
1531
1553
|
addExp(el, parsed.result)
|
|
1532
1554
|
}
|
|
@@ -1571,8 +1593,8 @@ function processClass (el, meta) {
|
|
|
1571
1593
|
let staticClass = getAndRemoveAttr(el, type).val || ''
|
|
1572
1594
|
staticClass = staticClass.replace(/\s+/g, ' ')
|
|
1573
1595
|
if (dynamicClass) {
|
|
1574
|
-
const staticClassExp =
|
|
1575
|
-
const dynamicClassExp = transDynamicClassExpr(
|
|
1596
|
+
const staticClassExp = parseMustacheWithContext(staticClass).result
|
|
1597
|
+
const dynamicClassExp = transDynamicClassExpr(parseMustacheWithContext(dynamicClass).result, {
|
|
1576
1598
|
error: error$1
|
|
1577
1599
|
})
|
|
1578
1600
|
addAttrs(el, [{
|
|
@@ -1607,8 +1629,8 @@ function processStyle (el, meta) {
|
|
|
1607
1629
|
let staticStyle = getAndRemoveAttr(el, type).val || ''
|
|
1608
1630
|
staticStyle = staticStyle.replace(/\s+/g, ' ')
|
|
1609
1631
|
if (dynamicStyle) {
|
|
1610
|
-
const staticStyleExp =
|
|
1611
|
-
const dynamicStyleExp =
|
|
1632
|
+
const staticStyleExp = parseMustacheWithContext(staticStyle).result
|
|
1633
|
+
const dynamicStyleExp = parseMustacheWithContext(dynamicStyle).result
|
|
1612
1634
|
addAttrs(el, [{
|
|
1613
1635
|
name: targetType,
|
|
1614
1636
|
value: `{{${stringifyModuleName}.stringifyStyle(${staticStyleExp}, ${dynamicStyleExp})}}`
|
|
@@ -1845,12 +1867,7 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1845
1867
|
}
|
|
1846
1868
|
if (options.isPage) {
|
|
1847
1869
|
if (mode === 'web') {
|
|
1848
|
-
return createASTElement('
|
|
1849
|
-
{
|
|
1850
|
-
name: 'class',
|
|
1851
|
-
value: 'page'
|
|
1852
|
-
}
|
|
1853
|
-
])
|
|
1870
|
+
return createASTElement('page', [])
|
|
1854
1871
|
}
|
|
1855
1872
|
}
|
|
1856
1873
|
}
|
|
@@ -1866,7 +1883,7 @@ function processShow (el, options, root) {
|
|
|
1866
1883
|
if (options.hasVirtualHost) {
|
|
1867
1884
|
if (options.isComponent && el.parent === root && isRealNode(el)) {
|
|
1868
1885
|
if (show !== undefined) {
|
|
1869
|
-
show = `{{${
|
|
1886
|
+
show = `{{${parseMustacheWithContext(show).result}&&mpxShow}}`
|
|
1870
1887
|
} else {
|
|
1871
1888
|
show = '{{mpxShow}}'
|
|
1872
1889
|
}
|
|
@@ -1888,7 +1905,7 @@ function processShow (el, options, root) {
|
|
|
1888
1905
|
|
|
1889
1906
|
function processShowStyle () {
|
|
1890
1907
|
if (show !== undefined) {
|
|
1891
|
-
const showExp =
|
|
1908
|
+
const showExp = parseMustacheWithContext(show).result
|
|
1892
1909
|
let oldStyle = getAndRemoveAttr(el, 'style').val
|
|
1893
1910
|
oldStyle = oldStyle ? oldStyle + ';' : ''
|
|
1894
1911
|
addAttrs(el, [{
|
|
@@ -2372,6 +2389,7 @@ module.exports = {
|
|
|
2372
2389
|
makeAttrsMap,
|
|
2373
2390
|
stringifyAttr,
|
|
2374
2391
|
parseMustache,
|
|
2392
|
+
parseMustacheWithContext,
|
|
2375
2393
|
stringifyWithResolveComputed,
|
|
2376
2394
|
addAttrs
|
|
2377
2395
|
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
// @mpxjs/webpack-plugin 2.7.x -> @mpxjs/core 2.7.x
|
|
2
|
-
// @mpxjs/webpack-plugin 2.8.x -> @mpxjs/core 2.8.x
|
|
3
1
|
const coreVersion = require('@mpxjs/core/package.json').version
|
|
4
|
-
const
|
|
5
|
-
const
|
|
2
|
+
const utilsVersion = require('@mpxjs/utils/package.json').version
|
|
3
|
+
const corePath = require.resolve('@mpxjs/core')
|
|
4
|
+
const utilsPath = require.resolve('@mpxjs/utils')
|
|
5
|
+
const semverLt = require('semver/functions/lt')
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const leastCoreVersion = '2.8.59'
|
|
8
|
+
const leastUtilsVersion = '2.8.59'
|
|
9
|
+
|
|
10
|
+
function compare (version, leastVersion, npmName, npmPath) {
|
|
11
|
+
if (semverLt(version, leastVersion)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`${npmName} packages version mismatch:
|
|
14
|
+
-${npmName}@${version}(${npmPath})
|
|
15
|
+
This may cause things to work incorrectly, Make sure the usage version is greater than ${leastVersion}.
|
|
16
16
|
`
|
|
17
|
-
|
|
17
|
+
)
|
|
18
|
+
}
|
|
18
19
|
}
|
|
20
|
+
|
|
21
|
+
compare(coreVersion, leastCoreVersion, '@mpxjs/core', corePath)
|
|
22
|
+
compare(utilsVersion, leastUtilsVersion, '@mpxjs/utils', utilsPath)
|
package/lib/web/processJSON.js
CHANGED
|
@@ -61,7 +61,8 @@ module.exports = function (json, {
|
|
|
61
61
|
customGetDynamicEntry (resource, type, outputPath, packageRoot) {
|
|
62
62
|
return {
|
|
63
63
|
resource,
|
|
64
|
-
outputPath
|
|
64
|
+
// 输出web时组件outputPath不需要拼接packageRoot
|
|
65
|
+
outputPath: type === 'page' ? toPosix(path.join(packageRoot, outputPath)) : outputPath,
|
|
65
66
|
packageRoot
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -297,7 +298,7 @@ module.exports = function (json, {
|
|
|
297
298
|
const processComponents = (components, context, callback) => {
|
|
298
299
|
if (components) {
|
|
299
300
|
async.eachOf(components, (component, name, callback) => {
|
|
300
|
-
processComponent(component, context, {}, (err, { resource, outputPath } = {}) => {
|
|
301
|
+
processComponent(component, context, {}, (err, { resource, outputPath } = {}, { tarRoot } = {}) => {
|
|
301
302
|
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
302
303
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
303
304
|
componentsMap[resourcePath] = outputPath
|
|
@@ -307,7 +308,7 @@ module.exports = function (json, {
|
|
|
307
308
|
isComponent: true,
|
|
308
309
|
outputPath
|
|
309
310
|
}),
|
|
310
|
-
async: queryObj.async
|
|
311
|
+
async: queryObj.async || tarRoot
|
|
311
312
|
}
|
|
312
313
|
callback()
|
|
313
314
|
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const addQuery = require('../utils/add-query')
|
|
2
|
+
const normalize = require('../utils/normalize')
|
|
3
|
+
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
4
|
+
const {
|
|
5
|
+
buildComponentsMap,
|
|
6
|
+
buildPagesMap,
|
|
7
|
+
buildGlobalParams,
|
|
8
|
+
shallowStringify,
|
|
9
|
+
stringifyRequest,
|
|
10
|
+
buildI18n
|
|
11
|
+
} = require('./script-helper')
|
|
12
|
+
|
|
13
|
+
module.exports = function (script, {
|
|
14
|
+
loaderContext,
|
|
15
|
+
ctorType,
|
|
16
|
+
srcMode,
|
|
17
|
+
moduleId,
|
|
18
|
+
isProduction,
|
|
19
|
+
jsonConfig,
|
|
20
|
+
localComponentsMap,
|
|
21
|
+
tabBar,
|
|
22
|
+
tabBarMap,
|
|
23
|
+
tabBarStr,
|
|
24
|
+
localPagesMap,
|
|
25
|
+
resource
|
|
26
|
+
}, callback) {
|
|
27
|
+
const { i18n, webConfig, hasUnoCSS } = loaderContext.getMpx()
|
|
28
|
+
const { pagesMap, firstPage, globalTabBar } = buildPagesMap({
|
|
29
|
+
localPagesMap,
|
|
30
|
+
loaderContext,
|
|
31
|
+
tabBar,
|
|
32
|
+
tabBarMap,
|
|
33
|
+
tabBarStr,
|
|
34
|
+
jsonConfig
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const componentsMap = buildComponentsMap({ localComponentsMap, loaderContext })
|
|
38
|
+
|
|
39
|
+
const scriptSrcMode = script ? script.mode || srcMode : srcMode
|
|
40
|
+
|
|
41
|
+
let output = ' import \'@mpxjs/webpack-plugin/lib/runtime/base.styl\'\n'
|
|
42
|
+
// hasUnoCSS由@mpxjs/unocss-plugin注入
|
|
43
|
+
if (hasUnoCSS) {
|
|
44
|
+
output += ' import \'uno.css\'\n'
|
|
45
|
+
}
|
|
46
|
+
output += ` import Vue from 'vue'
|
|
47
|
+
import VueRouter from 'vue-router'
|
|
48
|
+
import Mpx from '@mpxjs/core'
|
|
49
|
+
import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
50
|
+
Vue.use(VueRouter)\n`
|
|
51
|
+
|
|
52
|
+
if (i18n) {
|
|
53
|
+
output += buildI18n({ i18n, loaderContext })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
output += buildGlobalParams({
|
|
57
|
+
moduleId,
|
|
58
|
+
scriptSrcMode,
|
|
59
|
+
loaderContext,
|
|
60
|
+
isProduction,
|
|
61
|
+
jsonConfig,
|
|
62
|
+
webConfig,
|
|
63
|
+
isMain: true,
|
|
64
|
+
globalTabBar
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
output += `\n const App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`
|
|
68
|
+
|
|
69
|
+
output += `
|
|
70
|
+
export default processAppOption({
|
|
71
|
+
App,
|
|
72
|
+
tabBarMap: ${JSON.stringify(tabBarMap)},
|
|
73
|
+
firstPage: ${JSON.stringify(firstPage)},
|
|
74
|
+
pagesMap: ${shallowStringify(pagesMap)},
|
|
75
|
+
componentsMap: ${shallowStringify(componentsMap)},
|
|
76
|
+
Vue,
|
|
77
|
+
VueRouter,
|
|
78
|
+
webConfig: ${JSON.stringify(webConfig)}
|
|
79
|
+
})\n`
|
|
80
|
+
|
|
81
|
+
callback(null, {
|
|
82
|
+
output
|
|
83
|
+
})
|
|
84
|
+
}
|