@mpxjs/webpack-plugin 2.7.0-beta.2 → 2.7.0-beta.6
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/CommonJsVariableDependency.js +2 -7
- package/lib/dependencies/DynamicEntryDependency.js +5 -1
- package/lib/dependencies/{RecordStaticResourceDependency.js → RecordResourceMapDependency.js} +12 -7
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +8 -7
- package/lib/extractor.js +5 -4
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +1 -0
- package/lib/index.js +136 -112
- package/lib/json-compiler/helper.js +14 -21
- package/lib/json-compiler/index.js +67 -51
- package/lib/json-compiler/plugin.js +21 -5
- package/lib/loader.js +27 -50
- package/lib/native-loader.js +28 -65
- package/lib/parser.js +1 -2
- package/lib/platform/json/wx/index.js +7 -2
- package/lib/platform/template/wx/component-config/button.js +3 -3
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- package/lib/resolver/AddEnvPlugin.js +3 -2
- package/lib/resolver/AddModePlugin.js +3 -2
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/web/getInnerListeners.js +51 -45
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/optionProcessor.js +5 -20
- package/lib/runtime/stringify.wxs +3 -3
- package/lib/selector.js +3 -6
- package/lib/style-compiler/index.js +4 -5
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +105 -45
- package/lib/template-compiler/index.js +3 -6
- package/lib/template-compiler/trans-dynamic-class-expr.js +3 -3
- package/lib/utils/const.js +5 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-json-content.js +41 -0
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -142
- package/lib/web/processScript.js +30 -24
- package/lib/web/processTemplate.js +56 -40
- package/lib/wxs/i18n-loader.js +1 -3
- package/lib/wxs/loader.js +6 -26
- package/lib/wxs/pre-loader.js +7 -8
- package/lib/wxss/processCss.js +44 -44
- package/package.json +8 -8
- package/lib/built-in-loader.js +0 -49
- package/lib/record-loader.js +0 -11
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
package/lib/web/processJSON.js
CHANGED
|
@@ -6,28 +6,30 @@ const parseRequest = require('../utils/parse-request')
|
|
|
6
6
|
const toPosix = require('../utils/to-posix')
|
|
7
7
|
const addQuery = require('../utils/add-query')
|
|
8
8
|
const parseComponent = require('../parser')
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const getJSONContent = require('../utils/get-json-content')
|
|
10
|
+
const resolve = require('../utils/resolve')
|
|
11
|
+
const createJSONHelper = require('../json-compiler/helper')
|
|
12
|
+
const { RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
13
|
+
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
11
14
|
|
|
12
|
-
module.exports = function (json,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const resolveMode = options.resolveMode
|
|
18
|
-
const pagesMap = options.pagesMap
|
|
19
|
-
const componentsMap = options.componentsMap
|
|
20
|
-
const pagesEntryMap = options.pagesEntryMap
|
|
21
|
-
const projectRoot = options.projectRoot
|
|
22
|
-
const pathHash = options.pathHash
|
|
15
|
+
module.exports = function (json, {
|
|
16
|
+
loaderContext,
|
|
17
|
+
pagesMap,
|
|
18
|
+
componentsMap
|
|
19
|
+
}, rawCallback) {
|
|
23
20
|
const localPagesMap = {}
|
|
24
21
|
const localComponentsMap = {}
|
|
25
|
-
const buildInfo = loaderContext._module.buildInfo
|
|
26
|
-
|
|
27
22
|
let output = '/* json */\n'
|
|
28
23
|
let jsonObj = {}
|
|
29
24
|
let tabBarMap
|
|
30
25
|
let tabBarStr
|
|
26
|
+
const mpx = loaderContext.getMpx()
|
|
27
|
+
const {
|
|
28
|
+
mode,
|
|
29
|
+
env,
|
|
30
|
+
projectRoot
|
|
31
|
+
} = mpx
|
|
32
|
+
|
|
31
33
|
const context = loaderContext.context
|
|
32
34
|
|
|
33
35
|
const emitWarning = (msg) => {
|
|
@@ -37,13 +39,31 @@ module.exports = function (json, options, rawCallback) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
const emitError = (msg) => {
|
|
40
|
-
|
|
41
|
-
new Error('[json compiler][' +
|
|
42
|
+
loaderContext.emitError(
|
|
43
|
+
new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
|
|
42
44
|
)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
46
48
|
|
|
49
|
+
const {
|
|
50
|
+
isUrlRequest,
|
|
51
|
+
urlToRequest,
|
|
52
|
+
processPage,
|
|
53
|
+
processComponent
|
|
54
|
+
} = createJSONHelper({
|
|
55
|
+
loaderContext,
|
|
56
|
+
emitWarning,
|
|
57
|
+
emitError,
|
|
58
|
+
customGetDynamicEntry (resource, type, outputPath, packageRoot) {
|
|
59
|
+
return {
|
|
60
|
+
resource,
|
|
61
|
+
outputPath: toPosix(path.join(packageRoot, outputPath)),
|
|
62
|
+
packageRoot
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
47
67
|
const callback = (err) => {
|
|
48
68
|
return rawCallback(err, {
|
|
49
69
|
output,
|
|
@@ -67,12 +87,6 @@ module.exports = function (json, options, rawCallback) {
|
|
|
67
87
|
|
|
68
88
|
const fs = loaderContext._compiler.inputFileSystem
|
|
69
89
|
|
|
70
|
-
const resolve = (context, request, callback) => {
|
|
71
|
-
const { queryObj } = parseRequest(request)
|
|
72
|
-
context = queryObj.context || context
|
|
73
|
-
return loaderContext.resolve(context, request, callback)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
90
|
const defaultTabbar = {
|
|
77
91
|
borderStyle: 'black',
|
|
78
92
|
position: 'bottom',
|
|
@@ -90,7 +104,7 @@ module.exports = function (json, options, rawCallback) {
|
|
|
90
104
|
tabBarStr = JSON.stringify(tabBar)
|
|
91
105
|
tabBarStr = tabBarStr.replace(/"(iconPath|selectedIconPath)":"([^"]+)"/g, function (matched, $1, $2) {
|
|
92
106
|
if (isUrlRequest($2, projectRoot)) {
|
|
93
|
-
return `"${$1}":require(${stringifyRequest(
|
|
107
|
+
return `"${$1}":require(${stringifyRequest(urlToRequest($2, projectRoot))})`
|
|
94
108
|
}
|
|
95
109
|
return matched
|
|
96
110
|
})
|
|
@@ -100,45 +114,37 @@ module.exports = function (json, options, rawCallback) {
|
|
|
100
114
|
|
|
101
115
|
const processPackages = (packages, context, callback) => {
|
|
102
116
|
if (packages) {
|
|
103
|
-
async.
|
|
104
|
-
const
|
|
105
|
-
const queryObj = parsed.queryObj
|
|
106
|
-
// readFile无法处理query
|
|
107
|
-
packagePath = parsed.resourcePath
|
|
117
|
+
async.each(packages, (packagePath, callback) => {
|
|
118
|
+
const { queryObj } = parseRequest(packagePath)
|
|
108
119
|
async.waterfall([
|
|
109
120
|
(callback) => {
|
|
110
|
-
resolve(context, packagePath, (err, result) => {
|
|
111
|
-
callback(err
|
|
121
|
+
resolve(context, packagePath, loaderContext, (err, result) => {
|
|
122
|
+
if (err) return callback(err)
|
|
123
|
+
const { rawResourcePath } = parseRequest(result)
|
|
124
|
+
callback(err, rawResourcePath)
|
|
112
125
|
})
|
|
113
126
|
},
|
|
114
127
|
(result, callback) => {
|
|
115
|
-
loaderContext.addDependency(result)
|
|
116
128
|
fs.readFile(result, (err, content) => {
|
|
117
129
|
if (err) return callback(err)
|
|
118
130
|
callback(err, result, content.toString('utf-8'))
|
|
119
131
|
})
|
|
120
132
|
},
|
|
121
133
|
(result, content, callback) => {
|
|
122
|
-
const
|
|
123
|
-
const extName = path.extname(filePath)
|
|
134
|
+
const extName = path.extname(result)
|
|
124
135
|
if (extName === '.mpx' || extName === '.vue') {
|
|
125
136
|
const parts = parseComponent(content, {
|
|
126
|
-
filePath,
|
|
137
|
+
filePath: result,
|
|
127
138
|
needMap: loaderContext.sourceMap,
|
|
128
139
|
mode,
|
|
129
|
-
defs,
|
|
130
140
|
env
|
|
131
141
|
})
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
callback(null, result, content)
|
|
138
|
-
})
|
|
139
|
-
}
|
|
142
|
+
getJSONContent(parts.json || {}, loaderContext, (err, content) => {
|
|
143
|
+
callback(err, result, content)
|
|
144
|
+
})
|
|
145
|
+
} else {
|
|
146
|
+
callback(null, result, content)
|
|
140
147
|
}
|
|
141
|
-
callback(null, result, content)
|
|
142
148
|
},
|
|
143
149
|
(result, content, callback) => {
|
|
144
150
|
try {
|
|
@@ -159,12 +165,17 @@ module.exports = function (json, options, rawCallback) {
|
|
|
159
165
|
pages: content.pages,
|
|
160
166
|
...queryObj
|
|
161
167
|
}
|
|
168
|
+
|
|
169
|
+
if (content.plugins) {
|
|
170
|
+
subPackage.plugins = content.plugins
|
|
171
|
+
}
|
|
172
|
+
|
|
162
173
|
processSelfQueue.push((callback) => {
|
|
163
174
|
processSubPackage(subPackage, context, callback)
|
|
164
175
|
})
|
|
165
176
|
} else {
|
|
166
177
|
processSelfQueue.push((callback) => {
|
|
167
|
-
processPages(content.pages,
|
|
178
|
+
processPages(content.pages, context, '', callback)
|
|
168
179
|
})
|
|
169
180
|
}
|
|
170
181
|
}
|
|
@@ -179,77 +190,41 @@ module.exports = function (json, options, rawCallback) {
|
|
|
179
190
|
callback()
|
|
180
191
|
}
|
|
181
192
|
}
|
|
182
|
-
],
|
|
193
|
+
], (err) => {
|
|
194
|
+
callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
195
|
+
})
|
|
183
196
|
}, callback)
|
|
184
197
|
} else {
|
|
185
198
|
callback()
|
|
186
199
|
}
|
|
187
200
|
}
|
|
188
201
|
|
|
189
|
-
const
|
|
190
|
-
const baseName = path.basename(resourcePath, ext)
|
|
191
|
-
return path.join('pages', baseName + pathHash(resourcePath), baseName)
|
|
192
|
-
}
|
|
202
|
+
const pageKeySet = new Set()
|
|
193
203
|
|
|
194
|
-
const processPages = (pages,
|
|
204
|
+
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
195
205
|
if (pages) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
page = page.src
|
|
202
|
-
}
|
|
203
|
-
if (!isUrlRequest(page, projectRoot)) return callback()
|
|
204
|
-
if (resolveMode === 'native') {
|
|
205
|
-
page = loaderUtils.urlToRequest(page, projectRoot)
|
|
206
|
-
}
|
|
207
|
-
resolve(context, page, (err, resource) => {
|
|
208
|
-
if (err) return callback(err)
|
|
206
|
+
async.each(pages, (page, callback) => {
|
|
207
|
+
processPage(page, context, tarRoot, (err, { resource, outputPath } = {}, { isFirst, key } = {}) => {
|
|
208
|
+
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
209
|
+
if (pageKeySet.has(key)) return callback()
|
|
210
|
+
pageKeySet.add(key)
|
|
209
211
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (let key in pagesMap) {
|
|
217
|
-
if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
218
|
-
emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
|
|
219
|
-
return callback()
|
|
220
|
-
}
|
|
212
|
+
if (localPagesMap[outputPath]) {
|
|
213
|
+
const { resourcePath: oldResourcePath } = parseRequest(localPagesMap[outputPath].resource)
|
|
214
|
+
if (oldResourcePath !== resourcePath) {
|
|
215
|
+
const oldOutputPath = outputPath
|
|
216
|
+
outputPath = mpx.getOutputPath(resourcePath, 'page', { conflictPath: outputPath })
|
|
217
|
+
emitWarning(new Error(`Current page [${resourcePath}] is registered with a conflict outputPath [${oldOutputPath}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
|
|
221
218
|
}
|
|
222
|
-
} else {
|
|
223
|
-
const relative = path.relative(context, resourcePath)
|
|
224
|
-
if (/^\./.test(relative)) {
|
|
225
|
-
// 如果当前page不存在于context中,对其进行重命名
|
|
226
|
-
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
227
|
-
emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
|
|
228
|
-
} else {
|
|
229
|
-
pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
|
|
230
|
-
// 如果当前page与已有page存在命名冲突,也进行重命名
|
|
231
|
-
for (let key in pagesMap) {
|
|
232
|
-
// 此处引入pagesEntryMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
|
|
233
|
-
if (pagesMap[key] === pageName && key !== resourcePath && pagesEntryMap[key] === loaderContext.resourcePath) {
|
|
234
|
-
const pageNameRaw = pageName
|
|
235
|
-
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
236
|
-
emitWarning(`Current page [${resourcePath}] is registered with a conflict page path [${pageNameRaw}] which is already existed in system, the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
|
|
237
|
-
break
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (pagesMap[resourcePath]) {
|
|
243
|
-
emitWarning(`Current page [${resourcePath}] which is imported from [${loaderContext.resourcePath}] has been registered in pagesMap already, it will be ignored, please check it and remove the redundant page declaration!`)
|
|
244
|
-
return callback()
|
|
245
219
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
220
|
+
|
|
221
|
+
pagesMap[resourcePath] = outputPath
|
|
222
|
+
loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
|
|
223
|
+
|
|
224
|
+
localPagesMap[outputPath] = {
|
|
225
|
+
resource: addQuery(resource, { isPage: true }),
|
|
251
226
|
async: tarRoot || queryObj.async,
|
|
252
|
-
isFirst
|
|
227
|
+
isFirst
|
|
253
228
|
}
|
|
254
229
|
callback()
|
|
255
230
|
})
|
|
@@ -261,10 +236,15 @@ module.exports = function (json, options, rawCallback) {
|
|
|
261
236
|
|
|
262
237
|
const processSubPackage = (subPackage, context, callback) => {
|
|
263
238
|
if (subPackage) {
|
|
239
|
+
if (typeof subPackage.root === 'string' && subPackage.root.startsWith('.')) {
|
|
240
|
+
emitError(`Current subpackage root [${subPackage.root}] is not allow starts with '.'`)
|
|
241
|
+
return callback()
|
|
242
|
+
}
|
|
264
243
|
let tarRoot = subPackage.tarRoot || subPackage.root || ''
|
|
265
244
|
let srcRoot = subPackage.srcRoot || subPackage.root || ''
|
|
266
245
|
if (!tarRoot) return callback()
|
|
267
|
-
|
|
246
|
+
context = path.join(context, srcRoot)
|
|
247
|
+
processPages(subPackage.pages, context, tarRoot, callback)
|
|
268
248
|
} else {
|
|
269
249
|
callback()
|
|
270
250
|
}
|
|
@@ -272,7 +252,7 @@ module.exports = function (json, options, rawCallback) {
|
|
|
272
252
|
|
|
273
253
|
const processSubPackages = (subPackages, context, callback) => {
|
|
274
254
|
if (subPackages) {
|
|
275
|
-
async.
|
|
255
|
+
async.each(subPackages, (subPackage, callback) => {
|
|
276
256
|
processSubPackage(subPackage, context, callback)
|
|
277
257
|
}, callback)
|
|
278
258
|
} else {
|
|
@@ -282,48 +262,38 @@ module.exports = function (json, options, rawCallback) {
|
|
|
282
262
|
|
|
283
263
|
const processComponents = (components, context, callback) => {
|
|
284
264
|
if (components) {
|
|
285
|
-
async.
|
|
286
|
-
processComponent(component,
|
|
265
|
+
async.eachOf(components, (component, name, callback) => {
|
|
266
|
+
processComponent(component, context, {}, (err, { resource, outputPath } = {}) => {
|
|
267
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
268
|
+
return callback()
|
|
269
|
+
}
|
|
270
|
+
const { resourcePath, queryObj } = parseRequest(resource)
|
|
271
|
+
componentsMap[resourcePath] = outputPath
|
|
272
|
+
loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
|
273
|
+
|
|
274
|
+
localComponentsMap[name] = {
|
|
275
|
+
resource: addQuery(resource, {
|
|
276
|
+
isComponent: true,
|
|
277
|
+
outputPath
|
|
278
|
+
}),
|
|
279
|
+
async: queryObj.async
|
|
280
|
+
}
|
|
281
|
+
callback()
|
|
282
|
+
})
|
|
287
283
|
}, callback)
|
|
288
284
|
} else {
|
|
289
285
|
callback()
|
|
290
286
|
}
|
|
291
287
|
}
|
|
292
288
|
|
|
293
|
-
const processComponent = (component, name, context, callback) => {
|
|
294
|
-
if (!isUrlRequest(component, projectRoot)) return callback()
|
|
295
|
-
|
|
296
|
-
if (resolveMode === 'native') {
|
|
297
|
-
component = loaderUtils.urlToRequest(component, projectRoot)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
resolve(context, component, (err, resource) => {
|
|
301
|
-
if (err) return callback(err)
|
|
302
|
-
const { resourcePath, queryObj } = parseRequest(resource)
|
|
303
|
-
const parsed = path.parse(resourcePath)
|
|
304
|
-
const componentId = parsed.name + pathHash(resourcePath)
|
|
305
|
-
|
|
306
|
-
buildInfo.packageName = 'main'
|
|
307
|
-
buildInfo.componentsMap = buildInfo.componentsMap || {}
|
|
308
|
-
buildInfo.componentsMap[resourcePath] = componentsMap[resourcePath] = componentId
|
|
309
|
-
|
|
310
|
-
localComponentsMap[name] = {
|
|
311
|
-
resource: addQuery(resource, { component: true, componentId }),
|
|
312
|
-
async: queryObj.async
|
|
313
|
-
}
|
|
314
|
-
callback()
|
|
315
|
-
})
|
|
316
|
-
}
|
|
317
|
-
|
|
318
289
|
const processGenerics = (generics, context, callback) => {
|
|
319
290
|
if (generics) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}, callback)
|
|
291
|
+
const genericsComponents = {}
|
|
292
|
+
Object.keys(generics).forEach((name) => {
|
|
293
|
+
const generic = generics[name]
|
|
294
|
+
if (generic.default) genericsComponents[`${name}default`] = generic.default
|
|
295
|
+
})
|
|
296
|
+
processComponents(genericsComponents, context, callback)
|
|
327
297
|
} else {
|
|
328
298
|
callback()
|
|
329
299
|
}
|
|
@@ -331,6 +301,7 @@ module.exports = function (json, options, rawCallback) {
|
|
|
331
301
|
|
|
332
302
|
async.parallel([
|
|
333
303
|
(callback) => {
|
|
304
|
+
// 添加首页标识
|
|
334
305
|
if (jsonObj.pages && jsonObj.pages[0]) {
|
|
335
306
|
if (typeof jsonObj.pages[0] !== 'string') {
|
|
336
307
|
jsonObj.pages[0].src = addQuery(jsonObj.pages[0].src, { isFirst: true })
|
|
@@ -338,7 +309,7 @@ module.exports = function (json, options, rawCallback) {
|
|
|
338
309
|
jsonObj.pages[0] = addQuery(jsonObj.pages[0], { isFirst: true })
|
|
339
310
|
}
|
|
340
311
|
}
|
|
341
|
-
processPages(jsonObj.pages,
|
|
312
|
+
processPages(jsonObj.pages, context, '', callback)
|
|
342
313
|
},
|
|
343
314
|
(callback) => {
|
|
344
315
|
processComponents(jsonObj.usingComponents, context, callback)
|
package/lib/web/processScript.js
CHANGED
|
@@ -2,7 +2,6 @@ const genComponentTag = require('../utils/gen-component-tag')
|
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
4
|
const normalize = require('../utils/normalize')
|
|
5
|
-
const builtInLoaderPath = normalize.lib('built-in-loader')
|
|
6
5
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
7
6
|
const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
|
|
8
7
|
const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
|
|
@@ -21,23 +20,29 @@ function shallowStringify (obj) {
|
|
|
21
20
|
return `{${arr.join(',')}}`
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
module.exports = function (script,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
module.exports = function (script, {
|
|
24
|
+
loaderContext,
|
|
25
|
+
ctorType,
|
|
26
|
+
srcMode,
|
|
27
|
+
isProduction,
|
|
28
|
+
componentGenerics,
|
|
29
|
+
jsonConfig,
|
|
30
|
+
outputPath,
|
|
31
|
+
tabBarMap,
|
|
32
|
+
tabBarStr,
|
|
33
|
+
builtInComponentsMap,
|
|
34
|
+
genericsInfo,
|
|
35
|
+
wxsModuleMap,
|
|
36
|
+
localComponentsMap,
|
|
37
|
+
localPagesMap
|
|
38
|
+
}, callback) {
|
|
39
|
+
const mpx = loaderContext.getMpx()
|
|
40
|
+
const {
|
|
41
|
+
i18n,
|
|
42
|
+
projectRoot
|
|
43
|
+
} = mpx
|
|
44
|
+
|
|
35
45
|
const tabBar = jsonConfig.tabBar
|
|
36
|
-
const tabBarMap = options.tabBarMap
|
|
37
|
-
const tabBarStr = options.tabBarStr
|
|
38
|
-
const genericsInfo = options.genericsInfo
|
|
39
|
-
const componentGenerics = options.componentGenerics
|
|
40
|
-
const forceDisableBuiltInLoader = options.forceDisableBuiltInLoader
|
|
41
46
|
|
|
42
47
|
const emitWarning = (msg) => {
|
|
43
48
|
loaderContext.emitWarning(
|
|
@@ -49,7 +54,7 @@ module.exports = function (script, options, callback) {
|
|
|
49
54
|
let tabBarPagesMap = {}
|
|
50
55
|
if (tabBar && tabBarMap) {
|
|
51
56
|
// 挂载tabBar组件
|
|
52
|
-
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, {
|
|
57
|
+
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
|
|
53
58
|
tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
|
|
54
59
|
// 挂载tabBar页面
|
|
55
60
|
Object.keys(tabBarMap).forEach((pagePath) => {
|
|
@@ -161,9 +166,9 @@ module.exports = function (script, options, callback) {
|
|
|
161
166
|
}
|
|
162
167
|
// 注入wxs模块
|
|
163
168
|
content += ' const wxsModules = {}\n'
|
|
164
|
-
if (
|
|
165
|
-
Object.keys(
|
|
166
|
-
const src = loaderUtils.urlToRequest(
|
|
169
|
+
if (wxsModuleMap) {
|
|
170
|
+
Object.keys(wxsModuleMap).forEach((module) => {
|
|
171
|
+
const src = loaderUtils.urlToRequest(wxsModuleMap[module], projectRoot)
|
|
167
172
|
const expression = `require(${stringifyRequest(src)})`
|
|
168
173
|
content += ` wxsModules.${module} = ${expression}\n`
|
|
169
174
|
})
|
|
@@ -202,7 +207,7 @@ module.exports = function (script, options, callback) {
|
|
|
202
207
|
|
|
203
208
|
Object.keys(builtInComponentsMap).forEach((componentName) => {
|
|
204
209
|
const componentCfg = builtInComponentsMap[componentName]
|
|
205
|
-
const componentRequest =
|
|
210
|
+
const componentRequest = stringifyRequest(componentCfg.resource)
|
|
206
211
|
componentsMap[componentName] = `getComponent(require(${componentRequest}), { __mpxBuiltIn: true })`
|
|
207
212
|
})
|
|
208
213
|
|
|
@@ -211,10 +216,11 @@ module.exports = function (script, options, callback) {
|
|
|
211
216
|
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
212
217
|
}
|
|
213
218
|
// 为了正确获取currentSrcMode便于运行时进行转换,对于src引入的组件script采用require方式引入(由于webpack会将import的执行顺序上升至最顶),这意味着对于src引入脚本中的named export将不会生效,不过鉴于mpx和小程序中本身也没有在组件script中声明export的用法,所以应该没有影响
|
|
219
|
+
content += '\n\n\n/** ====== Source start ====== **/\n'
|
|
214
220
|
content += script.src
|
|
215
221
|
? `require(${stringifyRequest(script.src)})\n`
|
|
216
222
|
: script.content
|
|
217
|
-
content += '\n'
|
|
223
|
+
content += '\n/** ====== Source end ====== **/\n\n\n'
|
|
218
224
|
// createApp/Page/Component执行完成后立刻获取当前的option并暂存
|
|
219
225
|
content += ` const currentOption = global.currentOption\n`
|
|
220
226
|
// 获取pageConfig
|
|
@@ -245,7 +251,7 @@ module.exports = function (script, options, callback) {
|
|
|
245
251
|
currentOption,
|
|
246
252
|
${JSON.stringify(ctorType)},
|
|
247
253
|
${JSON.stringify(firstPage)},
|
|
248
|
-
${JSON.stringify(
|
|
254
|
+
${JSON.stringify(outputPath)},
|
|
249
255
|
${JSON.stringify(pageConfig)},
|
|
250
256
|
// @ts-ignore
|
|
251
257
|
${shallowStringify(pagesMap)},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const templateCompiler = require('../template-compiler/compiler')
|
|
2
2
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
|
-
const path = require('path')
|
|
5
4
|
const parseRequest = require('../utils/parse-request')
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
// const matchCondition = require('../utils/match-condition')
|
|
7
7
|
|
|
8
8
|
function calculateRootEleChild (arr) {
|
|
9
9
|
if (!arr) {
|
|
@@ -21,19 +21,30 @@ function calculateRootEleChild (arr) {
|
|
|
21
21
|
}, 0)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
module.exports = function (template,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
module.exports = function (template, {
|
|
25
|
+
loaderContext,
|
|
26
|
+
// hasScoped,
|
|
27
|
+
hasComment,
|
|
28
|
+
isNative,
|
|
29
|
+
srcMode,
|
|
30
|
+
moduleId,
|
|
31
|
+
ctorType,
|
|
32
|
+
usingComponents,
|
|
33
|
+
componentGenerics
|
|
34
|
+
}, callback) {
|
|
35
|
+
const mpx = loaderContext.getMpx()
|
|
36
|
+
const {
|
|
37
|
+
mode,
|
|
38
|
+
defs,
|
|
39
|
+
wxsContentMap,
|
|
40
|
+
decodeHTMLText,
|
|
41
|
+
externalClasses,
|
|
42
|
+
checkUsingComponents
|
|
43
|
+
// autoVirtualHostRules
|
|
44
|
+
} = mpx
|
|
45
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
32
46
|
const builtInComponentsMap = {}
|
|
33
|
-
|
|
34
|
-
const mainCompilation = getMainCompilation(compilation)
|
|
35
|
-
const mpx = mainCompilation.__mpx__
|
|
36
|
-
const wxsContentMap = mpx.wxsContentMap
|
|
47
|
+
|
|
37
48
|
let wxsModuleMap, genericsInfo
|
|
38
49
|
let output = '/* template */\n'
|
|
39
50
|
|
|
@@ -43,7 +54,7 @@ module.exports = function (template, options, callback) {
|
|
|
43
54
|
content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
|
|
44
55
|
}
|
|
45
56
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
46
|
-
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', {
|
|
57
|
+
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -62,7 +73,7 @@ module.exports = function (template, options, callback) {
|
|
|
62
73
|
}
|
|
63
74
|
if (template.content) {
|
|
64
75
|
const templateSrcMode = template.mode || srcMode
|
|
65
|
-
const
|
|
76
|
+
const { root, meta } = templateCompiler.parse(template.content, {
|
|
66
77
|
warn: (msg) => {
|
|
67
78
|
loaderContext.emitWarning(
|
|
68
79
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
@@ -73,54 +84,59 @@ module.exports = function (template, options, callback) {
|
|
|
73
84
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
74
85
|
)
|
|
75
86
|
},
|
|
76
|
-
usingComponents
|
|
77
|
-
hasComment
|
|
78
|
-
isNative
|
|
79
|
-
basename: path.basename(resourcePath),
|
|
87
|
+
usingComponents,
|
|
88
|
+
hasComment,
|
|
89
|
+
isNative,
|
|
80
90
|
isComponent: ctorType === 'component',
|
|
81
91
|
mode,
|
|
82
92
|
srcMode: templateSrcMode,
|
|
83
93
|
defs,
|
|
84
|
-
decodeHTMLText
|
|
85
|
-
externalClasses
|
|
94
|
+
decodeHTMLText,
|
|
95
|
+
externalClasses,
|
|
86
96
|
// todo 后续输出web也采用mpx的scoped处理
|
|
87
|
-
// hasScoped:options.hasScoped,
|
|
88
97
|
hasScoped: false,
|
|
89
98
|
moduleId,
|
|
90
99
|
filePath: loaderContext.resourcePath,
|
|
91
100
|
i18n: null,
|
|
92
|
-
checkUsingComponents
|
|
101
|
+
checkUsingComponents,
|
|
93
102
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
94
103
|
globalComponents: [],
|
|
95
104
|
// web模式下实现抽象组件
|
|
96
|
-
componentGenerics
|
|
105
|
+
componentGenerics
|
|
106
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
107
|
+
// hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
97
108
|
})
|
|
98
|
-
if (
|
|
99
|
-
wxsModuleMap =
|
|
109
|
+
if (meta.wxsModuleMap) {
|
|
110
|
+
wxsModuleMap = meta.wxsModuleMap
|
|
100
111
|
}
|
|
101
|
-
if (
|
|
102
|
-
for (let module in
|
|
103
|
-
wxsContentMap[`${resourcePath}~${module}`] =
|
|
112
|
+
if (meta.wxsContentMap) {
|
|
113
|
+
for (let module in meta.wxsContentMap) {
|
|
114
|
+
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
104
115
|
}
|
|
105
116
|
}
|
|
106
|
-
if (
|
|
107
|
-
Object.keys(
|
|
117
|
+
if (meta.builtInComponentsMap) {
|
|
118
|
+
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
108
119
|
builtInComponentsMap[name] = {
|
|
109
|
-
resource: addQuery(
|
|
120
|
+
resource: addQuery(meta.builtInComponentsMap[name], { isComponent: true })
|
|
110
121
|
}
|
|
111
122
|
})
|
|
112
123
|
}
|
|
113
|
-
if (
|
|
114
|
-
genericsInfo =
|
|
124
|
+
if (meta.genericsInfo) {
|
|
125
|
+
genericsInfo = meta.genericsInfo
|
|
115
126
|
}
|
|
116
|
-
// 输出H5有多个root element时, 使用
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
// 输出H5有多个root element时, 使用mpx-root-view标签包裹
|
|
128
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
129
|
+
if (root.tag === 'temp-node') {
|
|
130
|
+
const childLen = calculateRootEleChild(root.children)
|
|
119
131
|
if (childLen >= 2) {
|
|
120
|
-
|
|
132
|
+
root.tag = 'div'
|
|
133
|
+
templateCompiler.addAttrs(root, [{
|
|
134
|
+
name: 'class',
|
|
135
|
+
value: 'mpx-root-view'
|
|
136
|
+
}])
|
|
121
137
|
}
|
|
122
138
|
}
|
|
123
|
-
return templateCompiler.serialize(
|
|
139
|
+
return templateCompiler.serialize(root)
|
|
124
140
|
}
|
|
125
141
|
})
|
|
126
142
|
output += '\n\n'
|
package/lib/wxs/i18n-loader.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// 该loader用于将用户定义的messages注入到i18n.wxs中
|
|
2
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
3
2
|
const loaderUtils = require('loader-utils')
|
|
4
3
|
|
|
5
4
|
module.exports = function (content) {
|
|
6
|
-
const
|
|
7
|
-
const i18n = mainCompilation.__mpx__.i18n
|
|
5
|
+
const i18n = this.getMpx().i18n
|
|
8
6
|
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__\n'
|
|
9
7
|
if (i18n) {
|
|
10
8
|
if (i18n.messages) {
|