@mpxjs/webpack-plugin 2.7.0-beta.5 → 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/{RecordStaticResourceDependency.js → RecordResourceMapDependency.js} +12 -7
- package/lib/dependencies/ResolveDependency.js +8 -7
- package/lib/extractor.js +4 -4
- package/lib/file-loader.js +2 -2
- package/lib/index.js +41 -49
- package/lib/json-compiler/helper.js +2 -1
- package/lib/json-compiler/index.js +11 -11
- package/lib/loader.js +18 -36
- package/lib/platform/json/wx/index.js +7 -2
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- 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/style-compiler/index.js +4 -5
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +100 -36
- package/lib/template-compiler/index.js +3 -6
- package/lib/template-compiler/trans-dynamic-class-expr.js +3 -3
- package/lib/utils/const.js +3 -1
- package/lib/web/processJSON.js +105 -113
- package/lib/web/processScript.js +30 -24
- package/lib/web/processTemplate.js +56 -37
- package/lib/wxs/loader.js +3 -4
- package/lib/wxs/pre-loader.js +4 -4
- package/lib/wxss/processCss.js +44 -44
- package/package.json +7 -7
- package/lib/built-in-loader.js +0 -45
- package/lib/record-loader.js +0 -11
package/lib/web/processJSON.js
CHANGED
|
@@ -7,18 +7,29 @@ const toPosix = require('../utils/to-posix')
|
|
|
7
7
|
const addQuery = require('../utils/add-query')
|
|
8
8
|
const parseComponent = require('../parser')
|
|
9
9
|
const getJSONContent = require('../utils/get-json-content')
|
|
10
|
-
const isUrlRequest = require('../utils/is-url-request')
|
|
11
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')
|
|
12
14
|
|
|
13
|
-
module.exports = function (json, {
|
|
15
|
+
module.exports = function (json, {
|
|
16
|
+
loaderContext,
|
|
17
|
+
pagesMap,
|
|
18
|
+
componentsMap
|
|
19
|
+
}, rawCallback) {
|
|
14
20
|
const localPagesMap = {}
|
|
15
21
|
const localComponentsMap = {}
|
|
16
|
-
const buildInfo = loaderContext._module.buildInfo
|
|
17
|
-
|
|
18
22
|
let output = '/* json */\n'
|
|
19
23
|
let jsonObj = {}
|
|
20
24
|
let tabBarMap
|
|
21
25
|
let tabBarStr
|
|
26
|
+
const mpx = loaderContext.getMpx()
|
|
27
|
+
const {
|
|
28
|
+
mode,
|
|
29
|
+
env,
|
|
30
|
+
projectRoot
|
|
31
|
+
} = mpx
|
|
32
|
+
|
|
22
33
|
const context = loaderContext.context
|
|
23
34
|
|
|
24
35
|
const emitWarning = (msg) => {
|
|
@@ -28,13 +39,31 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
const emitError = (msg) => {
|
|
31
|
-
|
|
32
|
-
new Error('[json compiler][' +
|
|
42
|
+
loaderContext.emitError(
|
|
43
|
+
new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
|
|
33
44
|
)
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
37
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
|
+
|
|
38
67
|
const callback = (err) => {
|
|
39
68
|
return rawCallback(err, {
|
|
40
69
|
output,
|
|
@@ -75,7 +104,7 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
75
104
|
tabBarStr = JSON.stringify(tabBar)
|
|
76
105
|
tabBarStr = tabBarStr.replace(/"(iconPath|selectedIconPath)":"([^"]+)"/g, function (matched, $1, $2) {
|
|
77
106
|
if (isUrlRequest($2, projectRoot)) {
|
|
78
|
-
return `"${$1}":require(${stringifyRequest(
|
|
107
|
+
return `"${$1}":require(${stringifyRequest(urlToRequest($2, projectRoot))})`
|
|
79
108
|
}
|
|
80
109
|
return matched
|
|
81
110
|
})
|
|
@@ -85,15 +114,14 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
85
114
|
|
|
86
115
|
const processPackages = (packages, context, callback) => {
|
|
87
116
|
if (packages) {
|
|
88
|
-
async.
|
|
89
|
-
const
|
|
90
|
-
const queryObj = parsed.queryObj
|
|
91
|
-
// readFile无法处理query
|
|
92
|
-
packagePath = parsed.resourcePath
|
|
117
|
+
async.each(packages, (packagePath, callback) => {
|
|
118
|
+
const { queryObj } = parseRequest(packagePath)
|
|
93
119
|
async.waterfall([
|
|
94
120
|
(callback) => {
|
|
95
121
|
resolve(context, packagePath, loaderContext, (err, result) => {
|
|
96
|
-
callback(err
|
|
122
|
+
if (err) return callback(err)
|
|
123
|
+
const { rawResourcePath } = parseRequest(result)
|
|
124
|
+
callback(err, rawResourcePath)
|
|
97
125
|
})
|
|
98
126
|
},
|
|
99
127
|
(result, callback) => {
|
|
@@ -103,11 +131,10 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
103
131
|
})
|
|
104
132
|
},
|
|
105
133
|
(result, content, callback) => {
|
|
106
|
-
const
|
|
107
|
-
const extName = path.extname(filePath)
|
|
134
|
+
const extName = path.extname(result)
|
|
108
135
|
if (extName === '.mpx' || extName === '.vue') {
|
|
109
136
|
const parts = parseComponent(content, {
|
|
110
|
-
filePath,
|
|
137
|
+
filePath: result,
|
|
111
138
|
needMap: loaderContext.sourceMap,
|
|
112
139
|
mode,
|
|
113
140
|
env
|
|
@@ -138,12 +165,17 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
138
165
|
pages: content.pages,
|
|
139
166
|
...queryObj
|
|
140
167
|
}
|
|
168
|
+
|
|
169
|
+
if (content.plugins) {
|
|
170
|
+
subPackage.plugins = content.plugins
|
|
171
|
+
}
|
|
172
|
+
|
|
141
173
|
processSelfQueue.push((callback) => {
|
|
142
174
|
processSubPackage(subPackage, context, callback)
|
|
143
175
|
})
|
|
144
176
|
} else {
|
|
145
177
|
processSelfQueue.push((callback) => {
|
|
146
|
-
processPages(content.pages,
|
|
178
|
+
processPages(content.pages, context, '', callback)
|
|
147
179
|
})
|
|
148
180
|
}
|
|
149
181
|
}
|
|
@@ -158,77 +190,41 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
158
190
|
callback()
|
|
159
191
|
}
|
|
160
192
|
}
|
|
161
|
-
],
|
|
193
|
+
], (err) => {
|
|
194
|
+
callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
195
|
+
})
|
|
162
196
|
}, callback)
|
|
163
197
|
} else {
|
|
164
198
|
callback()
|
|
165
199
|
}
|
|
166
200
|
}
|
|
167
201
|
|
|
168
|
-
const
|
|
169
|
-
const baseName = path.basename(resourcePath, ext)
|
|
170
|
-
return path.join('pages', baseName + pathHash(resourcePath), baseName)
|
|
171
|
-
}
|
|
202
|
+
const pageKeySet = new Set()
|
|
172
203
|
|
|
173
|
-
const processPages = (pages,
|
|
204
|
+
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
174
205
|
if (pages) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
page = page.src
|
|
181
|
-
}
|
|
182
|
-
if (!isUrlRequest(page, projectRoot)) return callback()
|
|
183
|
-
if (resolveMode === 'native') {
|
|
184
|
-
page = loaderUtils.urlToRequest(page, projectRoot)
|
|
185
|
-
}
|
|
186
|
-
resolve(context, page, loaderContext, (err, resource) => {
|
|
187
|
-
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)
|
|
188
211
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
for (let key in pagesMap) {
|
|
196
|
-
if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
197
|
-
emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
|
|
198
|
-
return callback()
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
const relative = path.relative(context, resourcePath)
|
|
203
|
-
if (/^\./.test(relative)) {
|
|
204
|
-
// 如果当前page不存在于context中,对其进行重命名
|
|
205
|
-
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
206
|
-
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!`)
|
|
207
|
-
} else {
|
|
208
|
-
pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
|
|
209
|
-
// 如果当前page与已有page存在命名冲突,也进行重命名
|
|
210
|
-
for (let key in pagesMap) {
|
|
211
|
-
// 此处引入pagesEntryMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
|
|
212
|
-
if (pagesMap[key] === pageName && key !== resourcePath && pagesEntryMap[key] === loaderContext.resourcePath) {
|
|
213
|
-
const pageNameRaw = pageName
|
|
214
|
-
pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
215
|
-
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!`)
|
|
216
|
-
break
|
|
217
|
-
}
|
|
218
|
-
}
|
|
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!`))
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
pagesEntryMap[resourcePath] = loaderContext.resourcePath
|
|
228
|
-
localPagesMap[pageName] = {
|
|
229
|
-
resource: addQuery(resource, { page: true }),
|
|
220
|
+
|
|
221
|
+
pagesMap[resourcePath] = outputPath
|
|
222
|
+
loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
|
|
223
|
+
|
|
224
|
+
localPagesMap[outputPath] = {
|
|
225
|
+
resource: addQuery(resource, { isPage: true }),
|
|
230
226
|
async: tarRoot || queryObj.async,
|
|
231
|
-
isFirst
|
|
227
|
+
isFirst
|
|
232
228
|
}
|
|
233
229
|
callback()
|
|
234
230
|
})
|
|
@@ -240,10 +236,15 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
240
236
|
|
|
241
237
|
const processSubPackage = (subPackage, context, callback) => {
|
|
242
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
|
+
}
|
|
243
243
|
let tarRoot = subPackage.tarRoot || subPackage.root || ''
|
|
244
244
|
let srcRoot = subPackage.srcRoot || subPackage.root || ''
|
|
245
245
|
if (!tarRoot) return callback()
|
|
246
|
-
|
|
246
|
+
context = path.join(context, srcRoot)
|
|
247
|
+
processPages(subPackage.pages, context, tarRoot, callback)
|
|
247
248
|
} else {
|
|
248
249
|
callback()
|
|
249
250
|
}
|
|
@@ -251,7 +252,7 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
251
252
|
|
|
252
253
|
const processSubPackages = (subPackages, context, callback) => {
|
|
253
254
|
if (subPackages) {
|
|
254
|
-
async.
|
|
255
|
+
async.each(subPackages, (subPackage, callback) => {
|
|
255
256
|
processSubPackage(subPackage, context, callback)
|
|
256
257
|
}, callback)
|
|
257
258
|
} else {
|
|
@@ -261,48 +262,38 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
261
262
|
|
|
262
263
|
const processComponents = (components, context, callback) => {
|
|
263
264
|
if (components) {
|
|
264
|
-
async.
|
|
265
|
-
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
|
+
})
|
|
266
283
|
}, callback)
|
|
267
284
|
} else {
|
|
268
285
|
callback()
|
|
269
286
|
}
|
|
270
287
|
}
|
|
271
288
|
|
|
272
|
-
const processComponent = (component, name, context, callback) => {
|
|
273
|
-
if (!isUrlRequest(component, projectRoot)) return callback()
|
|
274
|
-
|
|
275
|
-
if (resolveMode === 'native') {
|
|
276
|
-
component = loaderUtils.urlToRequest(component, projectRoot)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
resolve(context, component, loaderContext, (err, resource) => {
|
|
280
|
-
if (err) return callback(err)
|
|
281
|
-
const { resourcePath, queryObj } = parseRequest(resource)
|
|
282
|
-
const parsed = path.parse(resourcePath)
|
|
283
|
-
const componentId = parsed.name + pathHash(resourcePath)
|
|
284
|
-
|
|
285
|
-
buildInfo.packageName = 'main'
|
|
286
|
-
buildInfo.componentsMap = buildInfo.componentsMap || {}
|
|
287
|
-
buildInfo.componentsMap[resourcePath] = componentsMap[resourcePath] = componentId
|
|
288
|
-
|
|
289
|
-
localComponentsMap[name] = {
|
|
290
|
-
resource: addQuery(resource, { component: true, componentId }),
|
|
291
|
-
async: queryObj.async
|
|
292
|
-
}
|
|
293
|
-
callback()
|
|
294
|
-
})
|
|
295
|
-
}
|
|
296
|
-
|
|
297
289
|
const processGenerics = (generics, context, callback) => {
|
|
298
290
|
if (generics) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}, 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)
|
|
306
297
|
} else {
|
|
307
298
|
callback()
|
|
308
299
|
}
|
|
@@ -310,6 +301,7 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
310
301
|
|
|
311
302
|
async.parallel([
|
|
312
303
|
(callback) => {
|
|
304
|
+
// 添加首页标识
|
|
313
305
|
if (jsonObj.pages && jsonObj.pages[0]) {
|
|
314
306
|
if (typeof jsonObj.pages[0] !== 'string') {
|
|
315
307
|
jsonObj.pages[0].src = addQuery(jsonObj.pages[0].src, { isFirst: true })
|
|
@@ -317,7 +309,7 @@ module.exports = function (json, { mode, env, loaderContext, resolveMode, pagesM
|
|
|
317
309
|
jsonObj.pages[0] = addQuery(jsonObj.pages[0], { isFirst: true })
|
|
318
310
|
}
|
|
319
311
|
}
|
|
320
|
-
processPages(jsonObj.pages,
|
|
312
|
+
processPages(jsonObj.pages, context, '', callback)
|
|
321
313
|
},
|
|
322
314
|
(callback) => {
|
|
323
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,10 @@
|
|
|
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
|
function calculateRootEleChild (arr) {
|
|
8
9
|
if (!arr) {
|
|
9
10
|
return 0
|
|
@@ -20,17 +21,30 @@ function calculateRootEleChild (arr) {
|
|
|
20
21
|
}, 0)
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
module.exports = function (template,
|
|
24
|
-
|
|
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) {
|
|
32
35
|
const mpx = loaderContext.getMpx()
|
|
33
|
-
const
|
|
36
|
+
const {
|
|
37
|
+
mode,
|
|
38
|
+
defs,
|
|
39
|
+
wxsContentMap,
|
|
40
|
+
decodeHTMLText,
|
|
41
|
+
externalClasses,
|
|
42
|
+
checkUsingComponents
|
|
43
|
+
// autoVirtualHostRules
|
|
44
|
+
} = mpx
|
|
45
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
46
|
+
const builtInComponentsMap = {}
|
|
47
|
+
|
|
34
48
|
let wxsModuleMap, genericsInfo
|
|
35
49
|
let output = '/* template */\n'
|
|
36
50
|
|
|
@@ -40,7 +54,7 @@ module.exports = function (template, options, callback) {
|
|
|
40
54
|
content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
|
|
41
55
|
}
|
|
42
56
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
43
|
-
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 })
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
60
|
|
|
@@ -59,7 +73,7 @@ module.exports = function (template, options, callback) {
|
|
|
59
73
|
}
|
|
60
74
|
if (template.content) {
|
|
61
75
|
const templateSrcMode = template.mode || srcMode
|
|
62
|
-
const
|
|
76
|
+
const { root, meta } = templateCompiler.parse(template.content, {
|
|
63
77
|
warn: (msg) => {
|
|
64
78
|
loaderContext.emitWarning(
|
|
65
79
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
@@ -70,54 +84,59 @@ module.exports = function (template, options, callback) {
|
|
|
70
84
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
71
85
|
)
|
|
72
86
|
},
|
|
73
|
-
usingComponents
|
|
74
|
-
hasComment
|
|
75
|
-
isNative
|
|
76
|
-
basename: path.basename(resourcePath),
|
|
87
|
+
usingComponents,
|
|
88
|
+
hasComment,
|
|
89
|
+
isNative,
|
|
77
90
|
isComponent: ctorType === 'component',
|
|
78
91
|
mode,
|
|
79
92
|
srcMode: templateSrcMode,
|
|
80
93
|
defs,
|
|
81
|
-
decodeHTMLText
|
|
82
|
-
externalClasses
|
|
94
|
+
decodeHTMLText,
|
|
95
|
+
externalClasses,
|
|
83
96
|
// todo 后续输出web也采用mpx的scoped处理
|
|
84
|
-
// hasScoped:options.hasScoped,
|
|
85
97
|
hasScoped: false,
|
|
86
98
|
moduleId,
|
|
87
99
|
filePath: loaderContext.resourcePath,
|
|
88
100
|
i18n: null,
|
|
89
|
-
checkUsingComponents
|
|
101
|
+
checkUsingComponents,
|
|
90
102
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
91
103
|
globalComponents: [],
|
|
92
104
|
// web模式下实现抽象组件
|
|
93
|
-
componentGenerics
|
|
105
|
+
componentGenerics
|
|
106
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
107
|
+
// hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
94
108
|
})
|
|
95
|
-
if (
|
|
96
|
-
wxsModuleMap =
|
|
109
|
+
if (meta.wxsModuleMap) {
|
|
110
|
+
wxsModuleMap = meta.wxsModuleMap
|
|
97
111
|
}
|
|
98
|
-
if (
|
|
99
|
-
for (let module in
|
|
100
|
-
wxsContentMap[`${resourcePath}~${module}`] =
|
|
112
|
+
if (meta.wxsContentMap) {
|
|
113
|
+
for (let module in meta.wxsContentMap) {
|
|
114
|
+
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
|
-
if (
|
|
104
|
-
Object.keys(
|
|
117
|
+
if (meta.builtInComponentsMap) {
|
|
118
|
+
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
105
119
|
builtInComponentsMap[name] = {
|
|
106
|
-
resource: addQuery(
|
|
120
|
+
resource: addQuery(meta.builtInComponentsMap[name], { isComponent: true })
|
|
107
121
|
}
|
|
108
122
|
})
|
|
109
123
|
}
|
|
110
|
-
if (
|
|
111
|
-
genericsInfo =
|
|
124
|
+
if (meta.genericsInfo) {
|
|
125
|
+
genericsInfo = meta.genericsInfo
|
|
112
126
|
}
|
|
113
|
-
// 输出H5有多个root element时, 使用
|
|
114
|
-
|
|
115
|
-
|
|
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)
|
|
116
131
|
if (childLen >= 2) {
|
|
117
|
-
|
|
132
|
+
root.tag = 'div'
|
|
133
|
+
templateCompiler.addAttrs(root, [{
|
|
134
|
+
name: 'class',
|
|
135
|
+
value: 'mpx-root-view'
|
|
136
|
+
}])
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
|
-
return templateCompiler.serialize(
|
|
139
|
+
return templateCompiler.serialize(root)
|
|
121
140
|
}
|
|
122
141
|
})
|
|
123
142
|
output += '\n\n'
|
package/lib/wxs/loader.js
CHANGED
|
@@ -3,7 +3,7 @@ const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
|
3
3
|
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const WxsPlugin = require('./WxsPlugin')
|
|
6
|
-
const
|
|
6
|
+
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
7
7
|
const parseRequest = require('../utils/parse-request')
|
|
8
8
|
const toPosix = require('../utils/to-posix')
|
|
9
9
|
const fixRelative = require('../utils/fix-relative')
|
|
@@ -14,7 +14,6 @@ module.exports = function () {
|
|
|
14
14
|
const moduleGraph = this._compilation.moduleGraph
|
|
15
15
|
const mpx = this.getMpx()
|
|
16
16
|
const mode = mpx.mode
|
|
17
|
-
const appInfo = mpx.appInfo
|
|
18
17
|
const getOutputPath = mpx.getOutputPath
|
|
19
18
|
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
20
19
|
const issuer = moduleGraph.getIssuer(this._module)
|
|
@@ -23,7 +22,7 @@ module.exports = function () {
|
|
|
23
22
|
const pagesMap = mpx.pagesMap
|
|
24
23
|
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
25
24
|
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
26
|
-
const issuerName =
|
|
25
|
+
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
27
26
|
const issuerDir = path.dirname(issuerName)
|
|
28
27
|
|
|
29
28
|
const getName = (raw) => {
|
|
@@ -38,7 +37,7 @@ module.exports = function () {
|
|
|
38
37
|
const packageRoot = queryObj.packageRoot || ''
|
|
39
38
|
const ext = config[mode].wxs.ext
|
|
40
39
|
const filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
|
|
41
|
-
this._module.addPresentationalDependency(new
|
|
40
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', filename, packageRoot))
|
|
42
41
|
|
|
43
42
|
const callback = (err) => {
|
|
44
43
|
if (err) return nativeCallback(err)
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const babylon = require('
|
|
2
|
-
const traverse = require('babel
|
|
3
|
-
const t = require('babel
|
|
4
|
-
const generate = require('babel
|
|
1
|
+
const babylon = require('@babel/parser')
|
|
2
|
+
const traverse = require('@babel/traverse').default
|
|
3
|
+
const t = require('@babel/types')
|
|
4
|
+
const generate = require('@babel/generator').default
|
|
5
5
|
const parseRequest = require('../utils/parse-request')
|
|
6
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
7
7
|
const parseQuery = require('loader-utils').parseQuery
|