@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
|
@@ -4,30 +4,26 @@ const nativeLoaderPath = normalize.lib('native-loader')
|
|
|
4
4
|
const isUrlRequestRaw = require('../utils/is-url-request')
|
|
5
5
|
const parseRequest = require('../utils/parse-request')
|
|
6
6
|
const loaderUtils = require('loader-utils')
|
|
7
|
+
const resolve = require('../utils/resolve')
|
|
7
8
|
|
|
8
|
-
module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
9
|
+
module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
|
|
9
10
|
const mpx = loaderContext.getMpx()
|
|
10
11
|
const resolveMode = mpx.resolveMode
|
|
11
12
|
const externals = mpx.externals
|
|
12
13
|
const root = mpx.projectRoot
|
|
13
14
|
const publicPath = loaderContext._compilation.outputOptions.publicPath || ''
|
|
14
15
|
const pathHash = mpx.pathHash
|
|
16
|
+
const getOutputPath = mpx.getOutputPath
|
|
15
17
|
|
|
16
18
|
const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
|
|
17
19
|
const urlToRequest = r => loaderUtils.urlToRequest(r)
|
|
18
20
|
|
|
19
|
-
// todo 提供不记录dependency的resolve方法,非必要的情况下不记录dependency,提升缓存利用率
|
|
20
|
-
const resolve = (context, request, callback) => {
|
|
21
|
-
const { queryObj } = parseRequest(request)
|
|
22
|
-
context = queryObj.context || context
|
|
23
|
-
return loaderContext.resolve(context, request, callback)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
const dynamicEntryMap = new Map()
|
|
27
22
|
|
|
28
23
|
let dynamicEntryCount = 0
|
|
29
24
|
|
|
30
25
|
const getDynamicEntry = (resource, type, outputPath = '', packageRoot = '', relativePath = '') => {
|
|
26
|
+
if (typeof customGetDynamicEntry === 'function') return customGetDynamicEntry(resource, type, outputPath, packageRoot, relativePath)
|
|
31
27
|
const key = `mpx_dynamic_entry_${dynamicEntryCount++}`
|
|
32
28
|
const value = `__mpx_dynamic_entry__( ${JSON.stringify(resource)},${JSON.stringify(type)},${JSON.stringify(outputPath)},${JSON.stringify(packageRoot)},${JSON.stringify(relativePath)})`
|
|
33
29
|
dynamicEntryMap.set(key, value)
|
|
@@ -47,7 +43,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
47
43
|
component = urlToRequest(component)
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
resolve(context, component, (err, resource, info) => {
|
|
46
|
+
resolve(context, component, loaderContext, (err, resource, info) => {
|
|
51
47
|
if (err) return callback(err)
|
|
52
48
|
const resourcePath = parseRequest(resource).resourcePath
|
|
53
49
|
const parsed = path.parse(resourcePath)
|
|
@@ -70,8 +66,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
70
66
|
let relative = path.relative(root, resourceName)
|
|
71
67
|
outputPath = path.join('components', name + pathHash(root), relative)
|
|
72
68
|
} else {
|
|
73
|
-
|
|
74
|
-
outputPath = path.join('components', componentName + pathHash(resourcePath), componentName)
|
|
69
|
+
outputPath = getOutputPath(resourcePath, 'component')
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
if (ext === '.js') {
|
|
@@ -83,11 +78,6 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
83
78
|
})
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
const getPageName = (resourcePath, ext) => {
|
|
87
|
-
const baseName = path.basename(resourcePath, ext)
|
|
88
|
-
return path.join('pages', baseName + pathHash(resourcePath), baseName)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
81
|
const processPage = (page, context, tarRoot = '', callback) => {
|
|
92
82
|
let aliasPath = ''
|
|
93
83
|
if (typeof page !== 'string') {
|
|
@@ -98,7 +88,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
98
88
|
if (resolveMode === 'native') {
|
|
99
89
|
page = urlToRequest(page)
|
|
100
90
|
}
|
|
101
|
-
resolve(context, page, (err, resource) => {
|
|
91
|
+
resolve(context, page, loaderContext, (err, resource) => {
|
|
102
92
|
if (err) return callback(err)
|
|
103
93
|
const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
|
|
104
94
|
const ext = path.extname(resourcePath)
|
|
@@ -109,7 +99,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
109
99
|
const relative = path.relative(context, resourcePath)
|
|
110
100
|
if (/^\./.test(relative)) {
|
|
111
101
|
// 如果当前page不存在于context中,对其进行重命名
|
|
112
|
-
outputPath =
|
|
102
|
+
outputPath = getOutputPath(resourcePath, 'page')
|
|
113
103
|
emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${outputPath}], use ?resolve to get the page path and navigate to it!`)
|
|
114
104
|
} else {
|
|
115
105
|
outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
|
|
@@ -119,7 +109,11 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
119
109
|
resource = `!!${nativeLoaderPath}!${resource}`
|
|
120
110
|
}
|
|
121
111
|
const entry = getDynamicEntry(resource, 'page', outputPath, tarRoot, publicPath + tarRoot)
|
|
122
|
-
|
|
112
|
+
const key = [resourcePath, outputPath, tarRoot].join('|')
|
|
113
|
+
callback(null, entry, {
|
|
114
|
+
isFirst,
|
|
115
|
+
key
|
|
116
|
+
})
|
|
123
117
|
})
|
|
124
118
|
}
|
|
125
119
|
|
|
@@ -127,7 +121,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
127
121
|
if (resolveMode === 'native') {
|
|
128
122
|
js = urlToRequest(js)
|
|
129
123
|
}
|
|
130
|
-
resolve(context, js, (err, resource) => {
|
|
124
|
+
resolve(context, js, loaderContext, (err, resource) => {
|
|
131
125
|
if (err) return callback(err)
|
|
132
126
|
const { resourcePath } = parseRequest(resource)
|
|
133
127
|
const relative = path.relative(context, resourcePath)
|
|
@@ -145,7 +139,6 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning }) {
|
|
|
145
139
|
processDynamicEntry,
|
|
146
140
|
processPage,
|
|
147
141
|
processJsExport,
|
|
148
|
-
resolve,
|
|
149
142
|
isUrlRequest,
|
|
150
143
|
urlToRequest
|
|
151
144
|
}
|
|
@@ -4,15 +4,16 @@ const path = require('path')
|
|
|
4
4
|
const parseComponent = require('../parser')
|
|
5
5
|
const config = require('../config')
|
|
6
6
|
const parseRequest = require('../utils/parse-request')
|
|
7
|
-
const
|
|
7
|
+
const evalJSONJS = require('../utils/eval-json-js')
|
|
8
8
|
const fixUsingComponent = require('../utils/fix-using-component')
|
|
9
9
|
const getRulesRunner = require('../platform/index')
|
|
10
10
|
const addQuery = require('../utils/add-query')
|
|
11
|
-
const
|
|
11
|
+
const getJSONContent = require('../utils/get-json-content')
|
|
12
12
|
const createHelpers = require('../helpers')
|
|
13
13
|
const createJSONHelper = require('./helper')
|
|
14
14
|
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
15
|
-
const { MPX_DISABLE_EXTRACTOR_CACHE } = require('../utils/const')
|
|
15
|
+
const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR, JSON_JS_EXT } = require('../utils/const')
|
|
16
|
+
const resolve = require('../utils/resolve')
|
|
16
17
|
|
|
17
18
|
module.exports = function (content) {
|
|
18
19
|
const nativeCallback = this.async()
|
|
@@ -27,13 +28,13 @@ module.exports = function (content) {
|
|
|
27
28
|
// 微信插件下要求组件使用相对路径
|
|
28
29
|
const useRelativePath = mpx.isPluginMode || mpx.useRelativePath
|
|
29
30
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
31
|
+
const useJSONJS = queryObj.useJSONJS || this.resourcePath.endsWith(JSON_JS_EXT)
|
|
30
32
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
31
33
|
const pagesMap = mpx.pagesMap
|
|
32
34
|
const componentsMap = mpx.componentsMap[packageName]
|
|
33
35
|
const appInfo = mpx.appInfo
|
|
34
36
|
const mode = mpx.mode
|
|
35
37
|
const env = mpx.env
|
|
36
|
-
const defs = mpx.defs
|
|
37
38
|
const globalSrcMode = mpx.srcMode
|
|
38
39
|
const localSrcMode = queryObj.mode
|
|
39
40
|
const srcMode = localSrcMode || globalSrcMode
|
|
@@ -55,7 +56,6 @@ module.exports = function (content) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
const {
|
|
58
|
-
resolve,
|
|
59
59
|
isUrlRequest,
|
|
60
60
|
urlToRequest,
|
|
61
61
|
processPage,
|
|
@@ -121,12 +121,10 @@ module.exports = function (content) {
|
|
|
121
121
|
nativeCallback(null, output)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
let json
|
|
124
|
+
let json
|
|
125
125
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (this.resourcePath.endsWith('.json.js')) {
|
|
129
|
-
json = JSON.parse(mpxJSON.compileMPXJSONText({ source: content, defs, filePath: this.resourcePath }))
|
|
126
|
+
if (useJSONJS) {
|
|
127
|
+
json = evalJSONJS(content, this.resourcePath, this)
|
|
130
128
|
} else {
|
|
131
129
|
json = JSON5.parse(content || '{}')
|
|
132
130
|
}
|
|
@@ -200,6 +198,10 @@ module.exports = function (content) {
|
|
|
200
198
|
if (components) {
|
|
201
199
|
async.eachOf(components, (component, name, callback) => {
|
|
202
200
|
processComponent(component, context, { relativePath }, (err, entry) => {
|
|
201
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
202
|
+
delete components[name]
|
|
203
|
+
return callback()
|
|
204
|
+
}
|
|
203
205
|
if (err) return callback(err)
|
|
204
206
|
components[name] = entry
|
|
205
207
|
callback()
|
|
@@ -214,20 +216,15 @@ module.exports = function (content) {
|
|
|
214
216
|
// app.json
|
|
215
217
|
const localPages = []
|
|
216
218
|
const subPackagesCfg = {}
|
|
217
|
-
|
|
218
|
-
if (json.pages && json.pages[0]) {
|
|
219
|
-
if (typeof json.pages[0] !== 'string') {
|
|
220
|
-
json.pages[0].src = addQuery(json.pages[0].src, { isFirst: true })
|
|
221
|
-
} else {
|
|
222
|
-
json.pages[0] = addQuery(json.pages[0], { isFirst: true })
|
|
223
|
-
}
|
|
224
|
-
}
|
|
219
|
+
const pageKeySet = new Set()
|
|
225
220
|
|
|
226
221
|
const processPages = (pages, context, tarRoot = '', callback) => {
|
|
227
222
|
if (pages) {
|
|
228
223
|
async.each(pages, (page, callback) => {
|
|
229
|
-
processPage(page, context, tarRoot, (err, entry, { isFirst } = {}) => {
|
|
230
|
-
if (err) return callback(err)
|
|
224
|
+
processPage(page, context, tarRoot, (err, entry, { isFirst, key } = {}) => {
|
|
225
|
+
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
226
|
+
if (pageKeySet.has(key)) return callback()
|
|
227
|
+
pageKeySet.add(key)
|
|
231
228
|
if (tarRoot && subPackagesCfg) {
|
|
232
229
|
subPackagesCfg[tarRoot].pages.push(entry)
|
|
233
230
|
} else {
|
|
@@ -252,13 +249,13 @@ module.exports = function (content) {
|
|
|
252
249
|
const { queryObj } = parseRequest(packagePath)
|
|
253
250
|
async.waterfall([
|
|
254
251
|
(callback) => {
|
|
255
|
-
resolve(context, packagePath, (err, result) => {
|
|
252
|
+
resolve(context, packagePath, this, (err, result) => {
|
|
253
|
+
if (err) return callback(err)
|
|
256
254
|
const { rawResourcePath } = parseRequest(result)
|
|
257
255
|
callback(err, rawResourcePath)
|
|
258
256
|
})
|
|
259
257
|
},
|
|
260
258
|
(result, callback) => {
|
|
261
|
-
this.addDependency(result)
|
|
262
259
|
fs.readFile(result, (err, content) => {
|
|
263
260
|
if (err) return callback(err)
|
|
264
261
|
callback(err, result, content.toString('utf-8'))
|
|
@@ -271,19 +268,14 @@ module.exports = function (content) {
|
|
|
271
268
|
filePath: result,
|
|
272
269
|
needMap: this.sourceMap,
|
|
273
270
|
mode,
|
|
274
|
-
defs,
|
|
275
271
|
env
|
|
276
272
|
})
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
callback(null, result, content)
|
|
283
|
-
})
|
|
284
|
-
}
|
|
273
|
+
getJSONContent(parts.json || {}, this, (err, content) => {
|
|
274
|
+
callback(err, result, content)
|
|
275
|
+
})
|
|
276
|
+
} else {
|
|
277
|
+
callback(null, result, content)
|
|
285
278
|
}
|
|
286
|
-
callback(null, result, content)
|
|
287
279
|
},
|
|
288
280
|
(result, content, callback) => {
|
|
289
281
|
try {
|
|
@@ -329,7 +321,9 @@ module.exports = function (content) {
|
|
|
329
321
|
callback()
|
|
330
322
|
}
|
|
331
323
|
}
|
|
332
|
-
],
|
|
324
|
+
], (err) => {
|
|
325
|
+
callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
326
|
+
})
|
|
333
327
|
}, callback)
|
|
334
328
|
} else {
|
|
335
329
|
callback()
|
|
@@ -451,17 +445,31 @@ module.exports = function (content) {
|
|
|
451
445
|
|
|
452
446
|
const processCustomTabBar = (tabBar, context, callback) => {
|
|
453
447
|
if (tabBar && tabBar.custom) {
|
|
454
|
-
processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' },
|
|
448
|
+
processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' }, (err) => {
|
|
449
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
450
|
+
delete tabBar.custom
|
|
451
|
+
return callback()
|
|
452
|
+
}
|
|
453
|
+
callback(err)
|
|
454
|
+
})
|
|
455
455
|
} else {
|
|
456
456
|
callback()
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
const processPluginGenericsImplementation = (
|
|
460
|
+
const processPluginGenericsImplementation = (plugin, context, tarRoot, callback) => {
|
|
461
|
+
if (!plugin.genericsImplementation) return callback()
|
|
461
462
|
const relativePath = useRelativePath ? publicPath + tarRoot : ''
|
|
462
|
-
async.eachOf(genericsImplementation, (genericComponents, name, callback) => {
|
|
463
|
+
async.eachOf(plugin.genericsImplementation, (genericComponents, name, callback) => {
|
|
463
464
|
async.eachOf(genericComponents, (genericComponentPath, name, callback) => {
|
|
464
|
-
processComponent(genericComponentPath, context, {
|
|
465
|
+
processComponent(genericComponentPath, context, {
|
|
466
|
+
tarRoot,
|
|
467
|
+
relativePath
|
|
468
|
+
}, (err, entry) => {
|
|
469
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
470
|
+
delete genericComponents[name]
|
|
471
|
+
return callback()
|
|
472
|
+
}
|
|
465
473
|
if (err) return callback(err)
|
|
466
474
|
genericComponents[name] = entry
|
|
467
475
|
})
|
|
@@ -470,10 +478,12 @@ module.exports = function (content) {
|
|
|
470
478
|
}
|
|
471
479
|
|
|
472
480
|
const processPluginExport = (plugin, context, tarRoot, callback) => {
|
|
473
|
-
if (!plugin.export)
|
|
474
|
-
return callback()
|
|
475
|
-
}
|
|
481
|
+
if (!plugin.export) return callback()
|
|
476
482
|
processJsExport(plugin.export, context, tarRoot, (err, entry) => {
|
|
483
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
484
|
+
delete plugin.export
|
|
485
|
+
return callback()
|
|
486
|
+
}
|
|
477
487
|
if (err) return callback(err)
|
|
478
488
|
plugin.export = entry
|
|
479
489
|
callback()
|
|
@@ -485,31 +495,33 @@ module.exports = function (content) {
|
|
|
485
495
|
async.eachOf(plugins, (plugin, name, callback) => {
|
|
486
496
|
async.parallel([
|
|
487
497
|
(callback) => {
|
|
488
|
-
|
|
489
|
-
processPluginGenericsImplementation(plugin.genericsImplementation, context, tarRoot, callback)
|
|
490
|
-
} else {
|
|
491
|
-
callback()
|
|
492
|
-
}
|
|
498
|
+
processPluginGenericsImplementation(plugin, context, tarRoot, callback)
|
|
493
499
|
},
|
|
494
500
|
(callback) => {
|
|
495
501
|
processPluginExport(plugin, context, tarRoot, callback)
|
|
496
502
|
}
|
|
497
|
-
],
|
|
498
|
-
callback(err)
|
|
499
|
-
})
|
|
503
|
+
], callback)
|
|
500
504
|
}, callback)
|
|
501
505
|
}
|
|
502
506
|
|
|
503
507
|
async.parallel([
|
|
504
508
|
(callback) => {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
509
|
+
// 添加首页标识
|
|
510
|
+
if (json.pages && json.pages[0]) {
|
|
511
|
+
if (typeof json.pages[0] !== 'string') {
|
|
512
|
+
json.pages[0].src = addQuery(json.pages[0].src, { isFirst: true })
|
|
513
|
+
} else {
|
|
514
|
+
json.pages[0] = addQuery(json.pages[0], { isFirst: true })
|
|
515
|
+
}
|
|
516
|
+
}
|
|
508
517
|
processPages(json.pages, this.context, '', callback)
|
|
509
518
|
},
|
|
510
519
|
(callback) => {
|
|
511
520
|
processComponents(json.usingComponents, this.context, callback)
|
|
512
521
|
},
|
|
522
|
+
(callback) => {
|
|
523
|
+
processPlugins(json.plugins, this.context, '', callback)
|
|
524
|
+
},
|
|
513
525
|
(callback) => {
|
|
514
526
|
processWorkers(json.workers, this.context, callback)
|
|
515
527
|
},
|
|
@@ -550,6 +562,10 @@ module.exports = function (content) {
|
|
|
550
562
|
async.eachOf(generics, (generic, name, callback) => {
|
|
551
563
|
if (generic.default) {
|
|
552
564
|
processComponent(generic.default, context, { relativePath }, (err, entry) => {
|
|
565
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
566
|
+
delete generic.default
|
|
567
|
+
return callback()
|
|
568
|
+
}
|
|
553
569
|
if (err) return callback(err)
|
|
554
570
|
generic.default = entry
|
|
555
571
|
callback()
|
|
@@ -2,7 +2,9 @@ const async = require('async')
|
|
|
2
2
|
const JSON5 = require('json5')
|
|
3
3
|
const getEntryName = require('../utils/get-entry-name')
|
|
4
4
|
const FlagPluginDependency = require('../dependencies/FlagPluginDependency')
|
|
5
|
+
const RemoveEntryDependency = require('../dependencies/RemoveEntryDependency')
|
|
5
6
|
const createJSONHelper = require('./helper')
|
|
7
|
+
const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR } = require('../utils/const')
|
|
6
8
|
|
|
7
9
|
module.exports = function (source) {
|
|
8
10
|
// 该loader中会在每次编译中动态添加entry,不能缓存,否则watch不好使
|
|
@@ -14,6 +16,9 @@ module.exports = function (source) {
|
|
|
14
16
|
return nativeCallback(null, source)
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
// json模块必须每次都创建(但并不是每次都需要build),用于动态添加编译入口,传递信息以禁用父级extractor的缓存
|
|
20
|
+
this.emitFile(MPX_DISABLE_EXTRACTOR_CACHE, '', undefined, { skipEmit: true })
|
|
21
|
+
|
|
17
22
|
this._module.addPresentationalDependency(new FlagPluginDependency())
|
|
18
23
|
|
|
19
24
|
const emitWarning = (msg) => {
|
|
@@ -45,7 +50,7 @@ module.exports = function (source) {
|
|
|
45
50
|
const srcMode = mpx.srcMode
|
|
46
51
|
const entryName = getEntryName(this)
|
|
47
52
|
// 最终输出中不需要为plugin.json产生chunk,而是使用extractor输出,删除plugin.json对应的entrypoint
|
|
48
|
-
if (entryName) this.
|
|
53
|
+
if (entryName) this._module.addPresentationalDependency(new RemoveEntryDependency(entryName))
|
|
49
54
|
|
|
50
55
|
// 新模式下plugin.json输出依赖于extractor
|
|
51
56
|
const callback = (err, processOutput) => {
|
|
@@ -66,6 +71,10 @@ module.exports = function (source) {
|
|
|
66
71
|
const processMain = (main, callback) => {
|
|
67
72
|
if (!main) return callback()
|
|
68
73
|
processJsExport(main, context, '', (err, entry) => {
|
|
74
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
75
|
+
delete pluginEntry.main
|
|
76
|
+
return callback()
|
|
77
|
+
}
|
|
69
78
|
if (err) return callback(err)
|
|
70
79
|
pluginEntry.main = entry
|
|
71
80
|
callback()
|
|
@@ -76,8 +85,12 @@ module.exports = function (source) {
|
|
|
76
85
|
if (!components) return callback()
|
|
77
86
|
async.eachOf(components, (component, name, callback) => {
|
|
78
87
|
processComponent(component, context, { relativePath }, (err, entry) => {
|
|
88
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
89
|
+
delete components[name]
|
|
90
|
+
return callback()
|
|
91
|
+
}
|
|
79
92
|
if (err) return callback(err)
|
|
80
|
-
|
|
93
|
+
components[name] = entry
|
|
81
94
|
callback()
|
|
82
95
|
})
|
|
83
96
|
}, callback)
|
|
@@ -105,15 +118,18 @@ module.exports = function (source) {
|
|
|
105
118
|
|
|
106
119
|
async.eachOf(pages, (page, key) => {
|
|
107
120
|
processPage(page, context, '', (err, entry) => {
|
|
121
|
+
if (err === RESOLVE_IGNORED_ERR) {
|
|
122
|
+
delete pages[key]
|
|
123
|
+
return callback()
|
|
124
|
+
}
|
|
108
125
|
if (err) return callback(err)
|
|
109
|
-
pages[key] = entry
|
|
110
126
|
if (mode === 'ali') {
|
|
111
127
|
pluginEntry.pages.push(entry)
|
|
112
128
|
if (!/^__private_page_\d+__$/.test(key)) {
|
|
113
129
|
pluginEntry.publicPages[key] = entry
|
|
114
130
|
}
|
|
115
131
|
} else {
|
|
116
|
-
|
|
132
|
+
pages[key] = entry
|
|
117
133
|
}
|
|
118
134
|
callback()
|
|
119
135
|
})
|
|
@@ -126,7 +142,7 @@ module.exports = function (source) {
|
|
|
126
142
|
}, (callback) => {
|
|
127
143
|
return processComponents(pluginEntry.publicComponents, callback)
|
|
128
144
|
}, (callback) => {
|
|
129
|
-
return processPages(pluginEntry.
|
|
145
|
+
return processPages(pluginEntry.pages, callback)
|
|
130
146
|
}
|
|
131
147
|
], (err) => {
|
|
132
148
|
return callback(err, processDynamicEntry)
|
package/lib/loader.js
CHANGED
|
@@ -11,10 +11,11 @@ const processJSON = require('./web/processJSON')
|
|
|
11
11
|
const processScript = require('./web/processScript')
|
|
12
12
|
const processStyles = require('./web/processStyles')
|
|
13
13
|
const processTemplate = require('./web/processTemplate')
|
|
14
|
-
const
|
|
14
|
+
const getJSONContent = require('./utils/get-json-content')
|
|
15
15
|
const normalize = require('./utils/normalize')
|
|
16
16
|
const getEntryName = require('./utils/get-entry-name')
|
|
17
17
|
const AppEntryDependency = require('./dependencies/AppEntryDependency')
|
|
18
|
+
const { MPX_APP_MODULE_ID } = require('./utils/const')
|
|
18
19
|
|
|
19
20
|
module.exports = function (content) {
|
|
20
21
|
this.cacheable()
|
|
@@ -27,11 +28,8 @@ module.exports = function (content) {
|
|
|
27
28
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
28
29
|
const pagesMap = mpx.pagesMap
|
|
29
30
|
const componentsMap = mpx.componentsMap[packageName]
|
|
30
|
-
const resolveMode = mpx.resolveMode
|
|
31
|
-
const projectRoot = mpx.projectRoot
|
|
32
31
|
const mode = mpx.mode
|
|
33
32
|
const env = mpx.env
|
|
34
|
-
const defs = mpx.defs
|
|
35
33
|
const i18n = mpx.i18n
|
|
36
34
|
const globalSrcMode = mpx.srcMode
|
|
37
35
|
const localSrcMode = queryObj.mode
|
|
@@ -39,10 +37,10 @@ module.exports = function (content) {
|
|
|
39
37
|
const vueContentCache = mpx.vueContentCache
|
|
40
38
|
const autoScope = matchCondition(resourcePath, mpx.autoScopeRules)
|
|
41
39
|
|
|
42
|
-
// 支持资源query传入
|
|
43
|
-
if ((queryObj.
|
|
40
|
+
// 支持资源query传入isPage或isComponent支持页面/组件单独编译
|
|
41
|
+
if ((queryObj.isComponent && !componentsMap[resourcePath]) || (queryObj.isPage && !pagesMap[resourcePath])) {
|
|
44
42
|
const entryName = getEntryName(this)
|
|
45
|
-
if (queryObj.
|
|
43
|
+
if (queryObj.isComponent) {
|
|
46
44
|
componentsMap[resourcePath] = entryName || 'noEntryComponent'
|
|
47
45
|
} else {
|
|
48
46
|
pagesMap[resourcePath] = entryName || 'noEntryPage'
|
|
@@ -58,24 +56,16 @@ module.exports = function (content) {
|
|
|
58
56
|
ctorType = 'component'
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
if (ctorType === 'app') {
|
|
62
|
-
const appName = getEntryName(this)
|
|
63
|
-
this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
59
|
const loaderContext = this
|
|
67
60
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
68
61
|
const isProduction = this.minimize || process.env.NODE_ENV === 'production'
|
|
69
|
-
|
|
70
62
|
const filePath = resourcePath
|
|
71
|
-
|
|
72
|
-
const moduleId = 'm' + mpx.pathHash(filePath)
|
|
63
|
+
const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : 'm' + mpx.pathHash(filePath)
|
|
73
64
|
|
|
74
65
|
const parts = parseComponent(content, {
|
|
75
66
|
filePath,
|
|
76
67
|
needMap: this.sourceMap,
|
|
77
68
|
mode,
|
|
78
|
-
defs,
|
|
79
69
|
env
|
|
80
70
|
})
|
|
81
71
|
|
|
@@ -84,16 +74,11 @@ module.exports = function (content) {
|
|
|
84
74
|
|
|
85
75
|
async.waterfall([
|
|
86
76
|
(callback) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (err) return callback(err)
|
|
91
|
-
json.content = result
|
|
92
|
-
callback()
|
|
93
|
-
})
|
|
94
|
-
} else {
|
|
77
|
+
getJSONContent(parts.json || {}, loaderContext, (err, content) => {
|
|
78
|
+
if (err) return callback(err)
|
|
79
|
+
if (parts.json) parts.json.content = content
|
|
95
80
|
callback()
|
|
96
|
-
}
|
|
81
|
+
})
|
|
97
82
|
},
|
|
98
83
|
(callback) => {
|
|
99
84
|
// web输出模式下没有任何inject,可以通过cache直接返回,由于读取src json可能会新增模块依赖,需要在之后返回缓存内容
|
|
@@ -126,8 +111,8 @@ module.exports = function (content) {
|
|
|
126
111
|
|
|
127
112
|
// 处理mode为web时输出vue格式文件
|
|
128
113
|
if (mode === 'web') {
|
|
129
|
-
if (ctorType === 'app' && !queryObj.
|
|
130
|
-
const request = addQuery(this.resource, {
|
|
114
|
+
if (ctorType === 'app' && !queryObj.isApp) {
|
|
115
|
+
const request = addQuery(this.resource, { isApp: true })
|
|
131
116
|
output += `
|
|
132
117
|
import App from ${stringifyRequest(request)}
|
|
133
118
|
import Vue from 'vue'
|
|
@@ -148,20 +133,15 @@ module.exports = function (content) {
|
|
|
148
133
|
async.parallel([
|
|
149
134
|
(callback) => {
|
|
150
135
|
processTemplate(parts.template, {
|
|
136
|
+
loaderContext,
|
|
151
137
|
hasScoped,
|
|
152
138
|
hasComment,
|
|
153
139
|
isNative,
|
|
154
|
-
mode,
|
|
155
140
|
srcMode,
|
|
156
|
-
defs,
|
|
157
|
-
loaderContext,
|
|
158
141
|
moduleId,
|
|
159
142
|
ctorType,
|
|
160
143
|
usingComponents,
|
|
161
|
-
componentGenerics
|
|
162
|
-
decodeHTMLText: mpx.decodeHTMLText,
|
|
163
|
-
externalClasses: mpx.externalClasses,
|
|
164
|
-
checkUsingComponents: mpx.checkUsingComponents
|
|
144
|
+
componentGenerics
|
|
165
145
|
}, callback)
|
|
166
146
|
},
|
|
167
147
|
(callback) => {
|
|
@@ -173,16 +153,9 @@ module.exports = function (content) {
|
|
|
173
153
|
},
|
|
174
154
|
(callback) => {
|
|
175
155
|
processJSON(parts.json, {
|
|
176
|
-
mode,
|
|
177
|
-
env,
|
|
178
|
-
defs,
|
|
179
|
-
resolveMode,
|
|
180
156
|
loaderContext,
|
|
181
157
|
pagesMap,
|
|
182
|
-
|
|
183
|
-
pathHash: mpx.pathHash,
|
|
184
|
-
componentsMap,
|
|
185
|
-
projectRoot
|
|
158
|
+
componentsMap
|
|
186
159
|
}, callback)
|
|
187
160
|
}
|
|
188
161
|
], (err, res) => {
|
|
@@ -198,23 +171,20 @@ module.exports = function (content) {
|
|
|
198
171
|
}
|
|
199
172
|
|
|
200
173
|
processScript(parts.script, {
|
|
174
|
+
loaderContext,
|
|
201
175
|
ctorType,
|
|
202
176
|
srcMode,
|
|
203
|
-
loaderContext,
|
|
204
177
|
isProduction,
|
|
205
|
-
i18n,
|
|
206
178
|
componentGenerics,
|
|
207
|
-
projectRoot,
|
|
208
179
|
jsonConfig: jsonRes.jsonObj,
|
|
209
|
-
|
|
180
|
+
outputPath: queryObj.outputPath || '',
|
|
210
181
|
tabBarMap: jsonRes.tabBarMap,
|
|
211
182
|
tabBarStr: jsonRes.tabBarStr,
|
|
212
183
|
builtInComponentsMap: templateRes.builtInComponentsMap,
|
|
213
184
|
genericsInfo: templateRes.genericsInfo,
|
|
214
185
|
wxsModuleMap: templateRes.wxsModuleMap,
|
|
215
186
|
localComponentsMap: jsonRes.localComponentsMap,
|
|
216
|
-
localPagesMap: jsonRes.localPagesMap
|
|
217
|
-
forceDisableBuiltInLoader: mpx.forceDisableBuiltInLoader
|
|
187
|
+
localPagesMap: jsonRes.localPagesMap
|
|
218
188
|
}, callback)
|
|
219
189
|
}
|
|
220
190
|
], (err, scriptRes) => {
|
|
@@ -225,6 +195,11 @@ module.exports = function (content) {
|
|
|
225
195
|
})
|
|
226
196
|
}
|
|
227
197
|
|
|
198
|
+
if (ctorType === 'app') {
|
|
199
|
+
const appName = getEntryName(this)
|
|
200
|
+
this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
|
|
201
|
+
}
|
|
202
|
+
|
|
228
203
|
const {
|
|
229
204
|
getRequire
|
|
230
205
|
} = createHelpers(loaderContext)
|
|
@@ -259,6 +234,7 @@ module.exports = function (content) {
|
|
|
259
234
|
output += `global.currentCtorType = ${JSON.stringify(ctor.replace(/^./, (match) => {
|
|
260
235
|
return match.toLowerCase()
|
|
261
236
|
}))}\n`
|
|
237
|
+
output += `global.currentResourceType = '${ctorType}'\n`
|
|
262
238
|
|
|
263
239
|
// template
|
|
264
240
|
output += '/* template */\n'
|
|
@@ -291,9 +267,10 @@ module.exports = function (content) {
|
|
|
291
267
|
}
|
|
292
268
|
// require style
|
|
293
269
|
if (style.src) {
|
|
294
|
-
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及
|
|
270
|
+
// style src会被特殊处理为全局复用样式,不添加resourcePath,添加isStatic及issuerFile
|
|
295
271
|
extraOptions.isStatic = true
|
|
296
|
-
|
|
272
|
+
const issuerResource = addQuery(this.resource, { type: 'styles' }, true)
|
|
273
|
+
extraOptions.issuerFile = mpx.getExtractedFile(issuerResource)
|
|
297
274
|
}
|
|
298
275
|
output += getRequire('styles', style, extraOptions, i) + '\n'
|
|
299
276
|
})
|