@mpxjs/webpack-plugin 2.7.0-beta.3 → 2.7.0-beta.7
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 +4 -4
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +1 -0
- package/lib/index.js +135 -109
- 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 +32 -48
- 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 +24 -27
- 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}`)
|
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,6 +503,15 @@ 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)
|
|
@@ -505,8 +523,7 @@ class MpxWebpackPlugin {
|
|
|
505
523
|
file = 'plugin.json'
|
|
506
524
|
} else if (isStatic) {
|
|
507
525
|
const packageRoot = queryObj.packageRoot || ''
|
|
508
|
-
|
|
509
|
-
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] })))
|
|
510
527
|
} else {
|
|
511
528
|
const appInfo = mpx.appInfo
|
|
512
529
|
const pagesMap = mpx.pagesMap
|
|
@@ -580,16 +597,15 @@ class MpxWebpackPlugin {
|
|
|
580
597
|
if (currentResourceMap[resourcePath] === outputPath) {
|
|
581
598
|
alreadyOutputed = true
|
|
582
599
|
} else {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
break
|
|
590
|
-
}
|
|
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
|
|
591
606
|
}
|
|
592
607
|
}
|
|
608
|
+
currentResourceMap[resourcePath] = outputPath
|
|
593
609
|
}
|
|
594
610
|
} else if (!currentResourceMap[resourcePath]) {
|
|
595
611
|
currentResourceMap[resourcePath] = true
|
|
@@ -611,8 +627,9 @@ class MpxWebpackPlugin {
|
|
|
611
627
|
async.forEach(presentationalDependencies.filter((dep) => dep.mpxAction), (dep, callback) => {
|
|
612
628
|
dep.mpxAction(module, compilation, callback)
|
|
613
629
|
}, (err) => {
|
|
614
|
-
|
|
615
|
-
|
|
630
|
+
rawProcessModuleDependencies.call(compilation, module, (innerErr) => {
|
|
631
|
+
return callback(err || innerErr)
|
|
632
|
+
})
|
|
616
633
|
})
|
|
617
634
|
}
|
|
618
635
|
|
|
@@ -685,17 +702,6 @@ class MpxWebpackPlugin {
|
|
|
685
702
|
}
|
|
686
703
|
})
|
|
687
704
|
|
|
688
|
-
// todo 统一通过dep+mpx actions处理
|
|
689
|
-
compilation.hooks.stillValidModule.tap('MpxWebpackPlugin', (module) => {
|
|
690
|
-
const buildInfo = module.buildInfo
|
|
691
|
-
if (buildInfo.pagesMap) {
|
|
692
|
-
Object.assign(mpx.pagesMap, buildInfo.pagesMap)
|
|
693
|
-
}
|
|
694
|
-
if (buildInfo.componentsMap && buildInfo.packageName) {
|
|
695
|
-
Object.assign(mpx.componentsMap[buildInfo.packageName], buildInfo.componentsMap)
|
|
696
|
-
}
|
|
697
|
-
})
|
|
698
|
-
|
|
699
705
|
compilation.hooks.finishModules.tap('MpxWebpackPlugin', (modules) => {
|
|
700
706
|
// 自动跟进分包配置修改splitChunksPlugin配置
|
|
701
707
|
if (splitChunksPlugin) {
|
|
@@ -726,6 +732,14 @@ class MpxWebpackPlugin {
|
|
|
726
732
|
return source
|
|
727
733
|
})
|
|
728
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
|
+
|
|
729
743
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
|
730
744
|
const extractedAssetsMap = new Map()
|
|
731
745
|
for (const module of compilation.modules) {
|
|
@@ -956,8 +970,6 @@ class MpxWebpackPlugin {
|
|
|
956
970
|
chunkLoadingGlobal
|
|
957
971
|
} = compilation.outputOptions
|
|
958
972
|
|
|
959
|
-
const { chunkGraph } = compilation
|
|
960
|
-
|
|
961
973
|
function getTargetFile (file) {
|
|
962
974
|
let targetFile = file
|
|
963
975
|
const queryStringIdx = targetFile.indexOf('?')
|
|
@@ -1023,6 +1035,7 @@ try {
|
|
|
1023
1035
|
context.setTimeout = setTimeout;
|
|
1024
1036
|
context.JSON = JSON;
|
|
1025
1037
|
context.Math = Math;
|
|
1038
|
+
context.Date = Date;
|
|
1026
1039
|
context.RegExp = RegExp;
|
|
1027
1040
|
context.Infinity = Infinity;
|
|
1028
1041
|
context.isFinite = isFinite;
|
|
@@ -1037,17 +1050,28 @@ try {
|
|
|
1037
1050
|
context.ArrayBuffer = ArrayBuffer;
|
|
1038
1051
|
context.Symbol = Symbol;
|
|
1039
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;
|
|
1040
1069
|
}
|
|
1041
1070
|
} catch(e){
|
|
1042
1071
|
}\n`)
|
|
1043
1072
|
source.add(originalSource)
|
|
1044
1073
|
source.add(`\nmodule.exports = ${globalObject}[${JSON.stringify(chunkLoadingGlobal)}];\n`)
|
|
1045
1074
|
} else {
|
|
1046
|
-
const entryModules = chunkGraph.getChunkEntryModulesIterable(chunk)
|
|
1047
|
-
const entryModule = entryModules && entryModules[0]
|
|
1048
|
-
if (entryModule && mpx.exportModules.has(entryModule)) {
|
|
1049
|
-
source.add('module.exports =\n')
|
|
1050
|
-
}
|
|
1051
1075
|
source.add(originalSource)
|
|
1052
1076
|
}
|
|
1053
1077
|
|
|
@@ -1124,7 +1148,7 @@ try {
|
|
|
1124
1148
|
if (loader.loader.includes(info[0])) {
|
|
1125
1149
|
loader.loader = info[1]
|
|
1126
1150
|
}
|
|
1127
|
-
if (loader.loader
|
|
1151
|
+
if (loader.loader.includes(info[1])) {
|
|
1128
1152
|
insertBeforeIndex = index
|
|
1129
1153
|
}
|
|
1130
1154
|
})
|
|
@@ -1159,41 +1183,43 @@ try {
|
|
|
1159
1183
|
loader: extractorPath
|
|
1160
1184
|
})
|
|
1161
1185
|
}
|
|
1162
|
-
|
|
1163
1186
|
createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
|
|
1164
|
-
createData.request = stringifyLoadersAndResource(loaders, createData.resource)
|
|
1165
1187
|
}
|
|
1166
1188
|
|
|
1167
|
-
|
|
1168
|
-
|
|
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
|
-
|
|
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)
|
|
1197
1223
|
// 根据用户传入的modeRules对特定资源添加mode query
|
|
1198
1224
|
this.runModeRules(createData)
|
|
1199
1225
|
})
|