@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
|
@@ -41,13 +41,10 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
41
41
|
dep,
|
|
42
42
|
source,
|
|
43
43
|
{
|
|
44
|
-
module,
|
|
45
44
|
runtimeTemplate,
|
|
46
45
|
moduleGraph,
|
|
47
46
|
chunkGraph,
|
|
48
|
-
runtimeRequirements
|
|
49
|
-
runtime,
|
|
50
|
-
initFragments
|
|
47
|
+
runtimeRequirements
|
|
51
48
|
}
|
|
52
49
|
) {
|
|
53
50
|
if (!dep.name) return
|
|
@@ -60,9 +57,7 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
60
57
|
runtimeRequirements
|
|
61
58
|
})
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
source.insert(0, requireExpr)
|
|
60
|
+
source.insert(0, `/* mpx cjs variable */ var ${dep.name} = ${requireExpr};\n`)
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
|
|
@@ -20,7 +20,8 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
get key () {
|
|
23
|
-
|
|
23
|
+
const { resource, entryType, outputPath, packageRoot, relativePath, range } = this
|
|
24
|
+
return [resource, entryType, outputPath, packageRoot, relativePath, ...range].join('|')
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
addEntry (compilation, callback) {
|
|
@@ -45,6 +46,9 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
45
46
|
resultPath = toPosix(path.relative(relativePath, resultPath))
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
// export类型的resultPath需要添加.js后缀
|
|
50
|
+
if (entryType === 'export') resultPath += '.js'
|
|
51
|
+
|
|
48
52
|
if (alreadyOutputed) return callback(null, { resultPath })
|
|
49
53
|
|
|
50
54
|
if (packageRoot) {
|
package/lib/dependencies/{RecordStaticResourceDependency.js → RecordResourceMapDependency.js}
RENAMED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
2
|
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
3
|
|
|
4
|
-
class
|
|
5
|
-
constructor (resourcePath, outputPath, packageRoot = '') {
|
|
4
|
+
class RecordResourceMapDependency extends NullDependency {
|
|
5
|
+
constructor (resourcePath, resourceType, outputPath, packageRoot = '') {
|
|
6
6
|
super()
|
|
7
7
|
this.resourcePath = resourcePath
|
|
8
|
+
this.resourceType = resourceType
|
|
8
9
|
this.outputPath = outputPath
|
|
9
10
|
this.packageRoot = packageRoot
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
get type () {
|
|
13
|
-
return 'mpx record
|
|
14
|
+
return 'mpx record resource map'
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
mpxAction (module, compilation, callback) {
|
|
17
18
|
const mpx = compilation.__mpx__
|
|
18
19
|
const packageName = this.packageRoot || 'main'
|
|
19
|
-
mpx
|
|
20
|
+
const resourceMap = mpx[`${this.resourceType}sMap`] || mpx.otherResourcesMap
|
|
21
|
+
const subResourceMap = resourceMap.main ? resourceMap[packageName] : resourceMap
|
|
22
|
+
subResourceMap[this.resourcePath] = this.outputPath
|
|
20
23
|
return callback()
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
serialize (context) {
|
|
24
27
|
const { write } = context
|
|
25
28
|
write(this.resourcePath)
|
|
29
|
+
write(this.resourceType)
|
|
26
30
|
write(this.outputPath)
|
|
27
31
|
write(this.packageRoot)
|
|
28
32
|
super.serialize(context)
|
|
@@ -31,17 +35,18 @@ class RecordStaticResourceDependency extends NullDependency {
|
|
|
31
35
|
deserialize (context) {
|
|
32
36
|
const { read } = context
|
|
33
37
|
this.resourcePath = read()
|
|
38
|
+
this.resourceType = read()
|
|
34
39
|
this.outputPath = read()
|
|
35
40
|
this.packageRoot = read()
|
|
36
41
|
super.deserialize(context)
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
RecordResourceMapDependency.Template = class RecordResourceMapDependencyTemplate {
|
|
41
46
|
apply () {
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
makeSerializable(
|
|
50
|
+
makeSerializable(RecordResourceMapDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordResourceMapDependency')
|
|
46
51
|
|
|
47
|
-
module.exports =
|
|
52
|
+
module.exports = RecordResourceMapDependency
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class RemoveEntryDependency extends NullDependency {
|
|
5
|
+
constructor (entryName) {
|
|
6
|
+
super()
|
|
7
|
+
this.entryName = entryName
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get type () {
|
|
11
|
+
return 'mpx remove entry'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
serialize (context) {
|
|
15
|
+
const { write } = context
|
|
16
|
+
write(this.entryName)
|
|
17
|
+
super.serialize(context)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
deserialize (context) {
|
|
21
|
+
const { read } = context
|
|
22
|
+
this.entryName = read()
|
|
23
|
+
super.deserialize(context)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
mpxAction (module, compilation, callback) {
|
|
27
|
+
const { entryName } = this
|
|
28
|
+
compilation.entries.delete(entryName)
|
|
29
|
+
return callback()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
RemoveEntryDependency.Template = class RemoveEntryDependencyTemplate {
|
|
34
|
+
apply () {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
makeSerializable(RemoveEntryDependency, '@mpxjs/webpack-plugin/lib/dependencies/RemoveEntryDependency')
|
|
39
|
+
|
|
40
|
+
module.exports = RemoveEntryDependency
|
|
@@ -37,8 +37,13 @@ class ResolveDependency extends NullDependency {
|
|
|
37
37
|
|
|
38
38
|
// resolved可能会动态变更,需用此更新hash
|
|
39
39
|
updateHash (hash, context) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
this.resolved = this.getResolved()
|
|
41
|
+
const { resource, issuerResource, compilation } = this
|
|
42
|
+
if (this.resolved) {
|
|
43
|
+
hash.update(this.resolved)
|
|
44
|
+
} else {
|
|
45
|
+
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
46
|
+
}
|
|
42
47
|
super.updateHash(hash, context)
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -68,12 +73,8 @@ ResolveDependency.Template = class ResolveDependencyTemplate {
|
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
getContent (dep) {
|
|
71
|
-
const {
|
|
76
|
+
const { resolved = '', compilation } = dep
|
|
72
77
|
const publicPath = compilation.outputOptions.publicPath || ''
|
|
73
|
-
const resolved = dep.getResolved()
|
|
74
|
-
if (!resolved) {
|
|
75
|
-
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
76
|
-
}
|
|
77
78
|
return JSON.stringify(publicPath + resolved)
|
|
78
79
|
}
|
|
79
80
|
}
|
package/lib/extractor.js
CHANGED
|
@@ -3,9 +3,9 @@ const loaderUtils = require('loader-utils')
|
|
|
3
3
|
const parseRequest = require('./utils/parse-request')
|
|
4
4
|
const toPosix = require('./utils/to-posix')
|
|
5
5
|
const fixRelative = require('./utils/fix-relative')
|
|
6
|
-
const normalize = require('./utils/normalize')
|
|
7
6
|
const addQuery = require('./utils/add-query')
|
|
8
7
|
const { MPX_DISABLE_EXTRACTOR_CACHE, DEFAULT_RESULT_SOURCE } = require('./utils/const')
|
|
8
|
+
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
9
9
|
|
|
10
10
|
module.exports = content => content
|
|
11
11
|
|
|
@@ -37,10 +37,10 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
let request = remainingRequest
|
|
40
|
-
// static
|
|
40
|
+
// static的情况下需要记录相关静态资源的输出路径
|
|
41
41
|
if (isStatic) {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const packageRoot = queryObj.packageRoot || ''
|
|
43
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', file, packageRoot))
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let content = await this.importModule(`!!${request}`)
|
|
@@ -87,6 +87,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
87
87
|
resultSource += `module.exports = ${JSON.stringify(relativePath)};\n`
|
|
88
88
|
} else {
|
|
89
89
|
this.emitFile(issuerFile, '', undefined, {
|
|
90
|
+
skipEmit: true,
|
|
90
91
|
extractedInfo: {
|
|
91
92
|
content: `@import "${relativePath}";\n`,
|
|
92
93
|
index: -1
|
package/lib/file-loader.js
CHANGED
|
@@ -2,7 +2,7 @@ const path = require('path')
|
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const toPosix = require('./utils/to-posix')
|
|
4
4
|
const parseRequest = require('./utils/parse-request')
|
|
5
|
-
const
|
|
5
|
+
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
6
6
|
|
|
7
7
|
module.exports = function loader (content, prevOptions) {
|
|
8
8
|
const options = prevOptions || loaderUtils.getOptions(this) || {}
|
|
@@ -28,7 +28,7 @@ module.exports = function loader (content, prevOptions) {
|
|
|
28
28
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
29
29
|
const packageRoot = queryObj.packageRoot || ''
|
|
30
30
|
url = outputPath = toPosix(path.join(packageRoot, outputPath))
|
|
31
|
-
this._module.addPresentationalDependency(new
|
|
31
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot))
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}`
|
package/lib/helpers.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -24,10 +24,11 @@ const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
|
|
|
24
24
|
// const RequireHeaderDependency = require('webpack/lib/dependencies/RequireHeaderDependency')
|
|
25
25
|
// const RemovedModuleDependency = require('./dependencies/RemovedModuleDependency')
|
|
26
26
|
const AppEntryDependency = require('./dependencies/AppEntryDependency')
|
|
27
|
-
const
|
|
27
|
+
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
28
28
|
const RecordGlobalComponentsDependency = require('./dependencies/RecordGlobalComponentsDependency')
|
|
29
29
|
const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
|
|
30
30
|
const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
|
|
31
|
+
const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
|
|
31
32
|
const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
|
|
32
33
|
const fixRelative = require('./utils/fix-relative')
|
|
33
34
|
const parseRequest = require('./utils/parse-request')
|
|
@@ -106,20 +107,20 @@ const externalsMap = {
|
|
|
106
107
|
const warnings = []
|
|
107
108
|
const errors = []
|
|
108
109
|
|
|
109
|
-
class EntryNode {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
110
|
+
// class EntryNode {
|
|
111
|
+
// constructor (options) {
|
|
112
|
+
// this.request = options.request
|
|
113
|
+
// this.type = options.type
|
|
114
|
+
// this.module = null
|
|
115
|
+
// this.parents = new Set()
|
|
116
|
+
// this.children = new Set()
|
|
117
|
+
// }
|
|
118
|
+
//
|
|
119
|
+
// addChild (node) {
|
|
120
|
+
// this.children.add(node)
|
|
121
|
+
// node.parents.add(this)
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
123
124
|
|
|
124
125
|
class MpxWebpackPlugin {
|
|
125
126
|
constructor (options = {}) {
|
|
@@ -177,6 +178,7 @@ class MpxWebpackPlugin {
|
|
|
177
178
|
options.fileConditionRules = options.fileConditionRules || {
|
|
178
179
|
include: () => true
|
|
179
180
|
}
|
|
181
|
+
options.customOutputPath = options.customOutputPath || null
|
|
180
182
|
this.options = options
|
|
181
183
|
}
|
|
182
184
|
|
|
@@ -184,35 +186,59 @@ class MpxWebpackPlugin {
|
|
|
184
186
|
if (options.transRpx) {
|
|
185
187
|
warnings.push('Mpx loader option [transRpx] is deprecated now, please use mpx webpack plugin config [transRpxRules] instead!')
|
|
186
188
|
}
|
|
187
|
-
return {
|
|
189
|
+
return {
|
|
190
|
+
loader: normalize.lib('loader'),
|
|
191
|
+
options
|
|
192
|
+
}
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
static nativeLoader (options = {}) {
|
|
191
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
loader: normalize.lib('native-loader'),
|
|
198
|
+
options
|
|
199
|
+
}
|
|
192
200
|
}
|
|
193
201
|
|
|
194
202
|
static wxssLoader (options) {
|
|
195
|
-
return {
|
|
203
|
+
return {
|
|
204
|
+
loader: normalize.lib('wxss/loader'),
|
|
205
|
+
options
|
|
206
|
+
}
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
static wxmlLoader (options) {
|
|
199
|
-
return {
|
|
210
|
+
return {
|
|
211
|
+
loader: normalize.lib('wxml/loader'),
|
|
212
|
+
options
|
|
213
|
+
}
|
|
200
214
|
}
|
|
201
215
|
|
|
202
216
|
static pluginLoader (options = {}) {
|
|
203
|
-
return {
|
|
217
|
+
return {
|
|
218
|
+
loader: normalize.lib('json-compiler/plugin'),
|
|
219
|
+
options
|
|
220
|
+
}
|
|
204
221
|
}
|
|
205
222
|
|
|
206
223
|
static wxsPreLoader (options = {}) {
|
|
207
|
-
return {
|
|
224
|
+
return {
|
|
225
|
+
loader: normalize.lib('wxs/pre-loader'),
|
|
226
|
+
options
|
|
227
|
+
}
|
|
208
228
|
}
|
|
209
229
|
|
|
210
230
|
static urlLoader (options = {}) {
|
|
211
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
loader: normalize.lib('url-loader'),
|
|
233
|
+
options
|
|
234
|
+
}
|
|
212
235
|
}
|
|
213
236
|
|
|
214
237
|
static fileLoader (options = {}) {
|
|
215
|
-
return {
|
|
238
|
+
return {
|
|
239
|
+
loader: normalize.lib('file-loader'),
|
|
240
|
+
options
|
|
241
|
+
}
|
|
216
242
|
}
|
|
217
243
|
|
|
218
244
|
runModeRules (data) {
|
|
@@ -359,7 +385,7 @@ class MpxWebpackPlugin {
|
|
|
359
385
|
})
|
|
360
386
|
|
|
361
387
|
compiler.hooks.compilation.tap('MpxWebpackPlugin ', (compilation, { normalModuleFactory }) => {
|
|
362
|
-
NormalModule.getCompilationHooks(compilation).loader.tap('MpxWebpackPlugin', (loaderContext
|
|
388
|
+
NormalModule.getCompilationHooks(compilation).loader.tap('MpxWebpackPlugin', (loaderContext) => {
|
|
363
389
|
// 设置loaderContext的minimize
|
|
364
390
|
if (isProductionLikeMode(compiler.options)) {
|
|
365
391
|
loaderContext.minimize = true
|
|
@@ -387,8 +413,11 @@ class MpxWebpackPlugin {
|
|
|
387
413
|
compilation.dependencyFactories.set(FlagPluginDependency, new NullFactory())
|
|
388
414
|
compilation.dependencyTemplates.set(FlagPluginDependency, new FlagPluginDependency.Template())
|
|
389
415
|
|
|
390
|
-
compilation.dependencyFactories.set(
|
|
391
|
-
compilation.dependencyTemplates.set(
|
|
416
|
+
compilation.dependencyFactories.set(RemoveEntryDependency, new NullFactory())
|
|
417
|
+
compilation.dependencyTemplates.set(RemoveEntryDependency, new RemoveEntryDependency.Template())
|
|
418
|
+
|
|
419
|
+
compilation.dependencyFactories.set(RecordResourceMapDependency, new NullFactory())
|
|
420
|
+
compilation.dependencyTemplates.set(RecordResourceMapDependency, new RecordResourceMapDependency.Template())
|
|
392
421
|
|
|
393
422
|
compilation.dependencyFactories.set(RecordGlobalComponentsDependency, new NullFactory())
|
|
394
423
|
compilation.dependencyTemplates.set(RecordGlobalComponentsDependency, new RecordGlobalComponentsDependency.Template())
|
|
@@ -436,7 +465,6 @@ class MpxWebpackPlugin {
|
|
|
436
465
|
// todo es6 map读写性能高于object,之后会逐步替换
|
|
437
466
|
vueContentCache: new Map(),
|
|
438
467
|
currentPackageRoot: '',
|
|
439
|
-
wxsMap: {},
|
|
440
468
|
wxsContentMap: {},
|
|
441
469
|
assetsInfo: new Map(),
|
|
442
470
|
forceUsePageCtor: this.options.forceUsePageCtor,
|
|
@@ -464,25 +492,6 @@ class MpxWebpackPlugin {
|
|
|
464
492
|
useRelativePath: this.options.useRelativePath,
|
|
465
493
|
removedChunks: [],
|
|
466
494
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
467
|
-
getEntryNode: (request, type, module) => {
|
|
468
|
-
const entryNodesMap = mpx.entryNodesMap
|
|
469
|
-
const entryModulesMap = mpx.entryModulesMap
|
|
470
|
-
if (!entryNodesMap[request]) {
|
|
471
|
-
entryNodesMap[request] = new EntryNode({
|
|
472
|
-
type,
|
|
473
|
-
request
|
|
474
|
-
})
|
|
475
|
-
}
|
|
476
|
-
const currentEntry = entryNodesMap[request]
|
|
477
|
-
if (currentEntry.type !== type) {
|
|
478
|
-
compilation.errors.push(`获取request为${request}的entryNode时类型与已有节点冲突, 当前获取的type为${type}, 已有节点的type为${currentEntry.type}!`)
|
|
479
|
-
}
|
|
480
|
-
if (module) {
|
|
481
|
-
currentEntry.module = module
|
|
482
|
-
entryModulesMap.set(module, currentEntry)
|
|
483
|
-
}
|
|
484
|
-
return currentEntry
|
|
485
|
-
},
|
|
486
495
|
pathHash: (resourcePath) => {
|
|
487
496
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
488
497
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -494,21 +503,27 @@ class MpxWebpackPlugin {
|
|
|
494
503
|
compilation.addEntry(compiler.context, dep, { name }, callback)
|
|
495
504
|
return dep
|
|
496
505
|
},
|
|
506
|
+
getOutputPath: (resourcePath, type, { ext = '', conflictPath = '' } = {}) => {
|
|
507
|
+
const name = path.parse(resourcePath).name
|
|
508
|
+
const hash = mpx.pathHash(resourcePath)
|
|
509
|
+
const customOutputPath = this.options.customOutputPath
|
|
510
|
+
if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
|
|
511
|
+
if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext)
|
|
512
|
+
if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
|
|
513
|
+
return path.join(type, name + hash + ext)
|
|
514
|
+
},
|
|
497
515
|
extractedFilesCache: new Map(),
|
|
498
516
|
getExtractedFile: (resource, { error } = {}) => {
|
|
499
517
|
const cache = mpx.extractedFilesCache.get(resource)
|
|
500
518
|
if (cache) return cache
|
|
501
519
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
502
|
-
const type = queryObj
|
|
503
|
-
const isStatic = queryObj.isStatic
|
|
504
|
-
const isPlugin = queryObj.isPlugin
|
|
520
|
+
const { type, isStatic, isPlugin } = queryObj
|
|
505
521
|
let file
|
|
506
522
|
if (isPlugin) {
|
|
507
523
|
file = 'plugin.json'
|
|
508
524
|
} else if (isStatic) {
|
|
509
525
|
const packageRoot = queryObj.packageRoot || ''
|
|
510
|
-
|
|
511
|
-
file = toPosix(path.join(packageRoot, type, resourceName + mpx.pathHash(resourcePath) + typeExtMap[type]))
|
|
526
|
+
file = toPosix(path.join(packageRoot, mpx.getOutputPath(resourcePath, type, { ext: typeExtMap[type] })))
|
|
512
527
|
} else {
|
|
513
528
|
const appInfo = mpx.appInfo
|
|
514
529
|
const pagesMap = mpx.pagesMap
|
|
@@ -582,16 +597,15 @@ class MpxWebpackPlugin {
|
|
|
582
597
|
if (currentResourceMap[resourcePath] === outputPath) {
|
|
583
598
|
alreadyOutputed = true
|
|
584
599
|
} else {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
break
|
|
592
|
-
}
|
|
600
|
+
// 输出冲突检测,如果存在输出路径冲突,对输出路径进行重命名
|
|
601
|
+
for (let key in currentResourceMap) {
|
|
602
|
+
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
603
|
+
outputPath = toPosix(path.join(packageRoot, mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })))
|
|
604
|
+
warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with a conflict outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
|
|
605
|
+
break
|
|
593
606
|
}
|
|
594
607
|
}
|
|
608
|
+
currentResourceMap[resourcePath] = outputPath
|
|
595
609
|
}
|
|
596
610
|
} else if (!currentResourceMap[resourcePath]) {
|
|
597
611
|
currentResourceMap[resourcePath] = true
|
|
@@ -613,8 +627,9 @@ class MpxWebpackPlugin {
|
|
|
613
627
|
async.forEach(presentationalDependencies.filter((dep) => dep.mpxAction), (dep, callback) => {
|
|
614
628
|
dep.mpxAction(module, compilation, callback)
|
|
615
629
|
}, (err) => {
|
|
616
|
-
|
|
617
|
-
|
|
630
|
+
rawProcessModuleDependencies.call(compilation, module, (innerErr) => {
|
|
631
|
+
return callback(err || innerErr)
|
|
632
|
+
})
|
|
618
633
|
})
|
|
619
634
|
}
|
|
620
635
|
|
|
@@ -687,17 +702,6 @@ class MpxWebpackPlugin {
|
|
|
687
702
|
}
|
|
688
703
|
})
|
|
689
704
|
|
|
690
|
-
// todo 统一通过dep+mpx actions处理
|
|
691
|
-
compilation.hooks.stillValidModule.tap('MpxWebpackPlugin', (module) => {
|
|
692
|
-
const buildInfo = module.buildInfo
|
|
693
|
-
if (buildInfo.pagesMap) {
|
|
694
|
-
Object.assign(mpx.pagesMap, buildInfo.pagesMap)
|
|
695
|
-
}
|
|
696
|
-
if (buildInfo.componentsMap && buildInfo.packageName) {
|
|
697
|
-
Object.assign(mpx.componentsMap[buildInfo.packageName], buildInfo.componentsMap)
|
|
698
|
-
}
|
|
699
|
-
})
|
|
700
|
-
|
|
701
705
|
compilation.hooks.finishModules.tap('MpxWebpackPlugin', (modules) => {
|
|
702
706
|
// 自动跟进分包配置修改splitChunksPlugin配置
|
|
703
707
|
if (splitChunksPlugin) {
|
|
@@ -728,6 +732,14 @@ class MpxWebpackPlugin {
|
|
|
728
732
|
return source
|
|
729
733
|
})
|
|
730
734
|
|
|
735
|
+
JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap('MpxWebpackPlugin', (source, module) => {
|
|
736
|
+
if (module && mpx.exportModules.has(module)) {
|
|
737
|
+
source = new ConcatSource(source)
|
|
738
|
+
source.add('module.exports = __webpack_exports__;\n')
|
|
739
|
+
}
|
|
740
|
+
return source
|
|
741
|
+
})
|
|
742
|
+
|
|
731
743
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
|
732
744
|
const extractedAssetsMap = new Map()
|
|
733
745
|
for (const module of compilation.modules) {
|
|
@@ -958,8 +970,6 @@ class MpxWebpackPlugin {
|
|
|
958
970
|
chunkLoadingGlobal
|
|
959
971
|
} = compilation.outputOptions
|
|
960
972
|
|
|
961
|
-
const { chunkGraph } = compilation
|
|
962
|
-
|
|
963
973
|
function getTargetFile (file) {
|
|
964
974
|
let targetFile = file
|
|
965
975
|
const queryStringIdx = targetFile.indexOf('?')
|
|
@@ -1025,6 +1035,7 @@ try {
|
|
|
1025
1035
|
context.setTimeout = setTimeout;
|
|
1026
1036
|
context.JSON = JSON;
|
|
1027
1037
|
context.Math = Math;
|
|
1038
|
+
context.Date = Date;
|
|
1028
1039
|
context.RegExp = RegExp;
|
|
1029
1040
|
context.Infinity = Infinity;
|
|
1030
1041
|
context.isFinite = isFinite;
|
|
@@ -1039,17 +1050,28 @@ try {
|
|
|
1039
1050
|
context.ArrayBuffer = ArrayBuffer;
|
|
1040
1051
|
context.Symbol = Symbol;
|
|
1041
1052
|
context.Reflect = Reflect;
|
|
1053
|
+
context.Object = Object;
|
|
1054
|
+
context.Error = Error;
|
|
1055
|
+
context.Array = Array;
|
|
1056
|
+
context.Float32Array = Float32Array;
|
|
1057
|
+
context.Float64Array = Float64Array;
|
|
1058
|
+
context.Int16Array = Int16Array;
|
|
1059
|
+
context.Int32Array = Int32Array;
|
|
1060
|
+
context.Int8Array = Int8Array;
|
|
1061
|
+
context.Uint16Array = Uint16Array;
|
|
1062
|
+
context.Uint32Array = Uint32Array;
|
|
1063
|
+
context.Uint8ClampedArray = Uint8ClampedArray;
|
|
1064
|
+
context.String = String;
|
|
1065
|
+
context.Function = Function;
|
|
1066
|
+
context.SyntaxError = SyntaxError;
|
|
1067
|
+
context.decodeURIComponent = decodeURIComponent;
|
|
1068
|
+
context.encodeURIComponent = encodeURIComponent;
|
|
1042
1069
|
}
|
|
1043
1070
|
} catch(e){
|
|
1044
1071
|
}\n`)
|
|
1045
1072
|
source.add(originalSource)
|
|
1046
1073
|
source.add(`\nmodule.exports = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}];\n`)
|
|
1047
1074
|
} else {
|
|
1048
|
-
const entryModules = chunkGraph.getChunkEntryModulesIterable(chunk)
|
|
1049
|
-
const entryModule = entryModules && entryModules[0]
|
|
1050
|
-
if (entryModule && mpx.exportModules.has(entryModule)) {
|
|
1051
|
-
source.add('module.exports =\n')
|
|
1052
|
-
}
|
|
1053
1075
|
source.add(originalSource)
|
|
1054
1076
|
}
|
|
1055
1077
|
|
|
@@ -1126,7 +1148,7 @@ try {
|
|
|
1126
1148
|
if (loader.loader.includes(info[0])) {
|
|
1127
1149
|
loader.loader = info[1]
|
|
1128
1150
|
}
|
|
1129
|
-
if (loader.loader
|
|
1151
|
+
if (loader.loader.includes(info[1])) {
|
|
1130
1152
|
insertBeforeIndex = index
|
|
1131
1153
|
}
|
|
1132
1154
|
})
|
|
@@ -1161,41 +1183,43 @@ try {
|
|
|
1161
1183
|
loader: extractorPath
|
|
1162
1184
|
})
|
|
1163
1185
|
}
|
|
1164
|
-
|
|
1165
1186
|
createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
|
|
1166
|
-
createData.request = stringifyLoadersAndResource(loaders, createData.resource)
|
|
1167
1187
|
}
|
|
1168
1188
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1189
|
+
if (mpx.mode === 'web') {
|
|
1190
|
+
const mpxStyleOptions = queryObj.mpxStyleOptions
|
|
1191
|
+
const firstLoader = (loaders[0] && loaders[0].loader) || ''
|
|
1192
|
+
const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
|
|
1193
|
+
let cssLoaderIndex = -1
|
|
1194
|
+
let vueStyleLoaderIndex = -1
|
|
1195
|
+
let mpxStyleLoaderIndex = -1
|
|
1196
|
+
loaders.forEach((loader, index) => {
|
|
1197
|
+
const currentLoader = loader.loader
|
|
1198
|
+
if (currentLoader.includes('css-loader')) {
|
|
1199
|
+
cssLoaderIndex = index
|
|
1200
|
+
} else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')) {
|
|
1201
|
+
vueStyleLoaderIndex = index
|
|
1202
|
+
} else if (currentLoader.includes(styleCompilerPath)) {
|
|
1203
|
+
mpxStyleLoaderIndex = index
|
|
1204
|
+
}
|
|
1205
|
+
})
|
|
1206
|
+
if (mpxStyleLoaderIndex === -1) {
|
|
1207
|
+
let loaderIndex = -1
|
|
1208
|
+
if (cssLoaderIndex > -1 && vueStyleLoaderIndex === -1) {
|
|
1209
|
+
loaderIndex = cssLoaderIndex
|
|
1210
|
+
} else if (cssLoaderIndex > -1 && vueStyleLoaderIndex > -1 && !isPitcherRequest) {
|
|
1211
|
+
loaderIndex = vueStyleLoaderIndex
|
|
1212
|
+
}
|
|
1213
|
+
if (loaderIndex > -1) {
|
|
1214
|
+
loaders.splice(loaderIndex + 1, 0, {
|
|
1215
|
+
loader: styleCompilerPath,
|
|
1216
|
+
options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {}
|
|
1217
|
+
})
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
createData.request = stringifyLoadersAndResource(loaders, createData.resource)
|
|
1199
1223
|
// 根据用户传入的modeRules对特定资源添加mode query
|
|
1200
1224
|
this.runModeRules(createData)
|
|
1201
1225
|
})
|