@mpxjs/webpack-plugin 2.6.114-alpha.6 → 2.6.114-alpha.9
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/{dependency → dependencies}/AddEntryDependency.js +0 -0
- package/lib/dependencies/AppEntryDependency.js +58 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +81 -0
- package/lib/dependencies/DynamicEntryDependency.js +171 -0
- package/lib/dependencies/FlagPluginDependency.js +24 -0
- package/lib/dependencies/InjectDependency.js +43 -0
- package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +88 -0
- package/lib/extractor.js +82 -178
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +39 -334
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +854 -542
- package/lib/json-compiler/helper.js +156 -0
- package/lib/json-compiler/index.js +242 -451
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +137 -240
- package/lib/native-loader.js +71 -133
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/index.js +30 -4
- package/lib/record-loader.js +11 -0
- package/lib/{path-loader.js → resolve-loader.js} +0 -0
- package/lib/resolver/AddEnvPlugin.js +4 -3
- package/lib/resolver/AddModePlugin.js +4 -3
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +23 -36
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +18 -3
- package/lib/runtime/i18n.wxs +31 -11
- package/lib/runtime/optionProcessor.js +48 -3
- package/lib/selector.js +29 -10
- package/lib/style-compiler/index.js +15 -23
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/rpx.js +43 -37
- package/lib/style-compiler/plugins/scope-id.js +79 -72
- package/lib/style-compiler/plugins/trans-special.js +25 -18
- package/lib/style-compiler/plugins/trim.js +13 -7
- package/lib/style-compiler/plugins/vw.js +22 -16
- package/lib/template-compiler/compiler.js +95 -197
- package/lib/template-compiler/index.js +52 -139
- package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
- package/lib/tenon/index.js +1 -4
- package/lib/tenon/processJSON.js +71 -76
- package/lib/tenon/processScript.js +60 -59
- package/lib/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +10 -0
- package/lib/utils/emit-file.js +10 -0
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +13 -0
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +2 -1
- package/lib/utils/is-url-request.js +10 -1
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -15
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/resolve.js +13 -0
- package/lib/utils/set.js +47 -0
- package/lib/utils/stringify-loaders-resource.js +25 -0
- package/lib/utils/stringify-query.js +4 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +47 -34
- package/lib/web/processTemplate.js +57 -40
- package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
- package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +4 -8
- package/lib/wxs/WxsTemplatePlugin.js +46 -92
- package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
- package/lib/wxs/loader.js +142 -0
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/lib/wxss/processCss.js +107 -103
- package/package.json +18 -20
- package/lib/built-in-loader.js +0 -49
- package/lib/content-loader.js +0 -13
- package/lib/dependency/ChildCompileDependency.js +0 -24
- package/lib/dependency/InjectDependency.js +0 -26
- package/lib/dependency/RemovedModuleDependency.js +0 -23
- package/lib/dependency/ResolveDependency.js +0 -53
- package/lib/plugin-loader.js +0 -287
- package/lib/staticConfig.js +0 -4
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
- package/lib/utils/try-require.js +0 -16
- package/lib/wxs/wxs-loader.js +0 -117
- package/lib/wxss/getImportPrefix.js +0 -30
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class AppEntryDependency extends NullDependency {
|
|
5
|
+
constructor (resourcePath, name) {
|
|
6
|
+
super()
|
|
7
|
+
this.resourcePath = resourcePath
|
|
8
|
+
this.name = name
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get type () {
|
|
12
|
+
return 'mpx app entry'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
mpxAction (module, compilation, callback) {
|
|
16
|
+
const mpx = compilation.__mpx__
|
|
17
|
+
const moduleGraph = compilation.moduleGraph
|
|
18
|
+
|
|
19
|
+
mpx.getEntryNode(module, 'app')
|
|
20
|
+
|
|
21
|
+
if (mpx.appInfo.name) {
|
|
22
|
+
const issuer = moduleGraph.getIssuer(module)
|
|
23
|
+
const err = new Error(issuer
|
|
24
|
+
? `[json compiler]:Mpx单次构建中只能存在一个App,当前组件/页面[${module.resource}]通过[${issuer.resource}]非法引入,引用的资源将被忽略,请确保组件/页面资源通过usingComponents/pages配置引入!`
|
|
25
|
+
: `[json compiler]:Mpx单次构建中只能存在一个App,请检查当前entry中的资源[${module.resource}]是否为组件/页面,通过添加?component/page查询字符串显式声明该资源是组件/页面!`)
|
|
26
|
+
return callback(err)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
mpx.appInfo = {
|
|
30
|
+
resourcePath: this.resourcePath,
|
|
31
|
+
name: this.name
|
|
32
|
+
}
|
|
33
|
+
return callback()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
serialize (context) {
|
|
37
|
+
const { write } = context
|
|
38
|
+
write(this.resourcePath)
|
|
39
|
+
write(this.name)
|
|
40
|
+
super.serialize(context)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
deserialize (context) {
|
|
44
|
+
const { read } = context
|
|
45
|
+
this.resourcePath = read()
|
|
46
|
+
this.name = read()
|
|
47
|
+
super.deserialize(context)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
AppEntryDependency.Template = class AppEntryDependencyTemplate {
|
|
52
|
+
apply () {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
makeSerializable(AppEntryDependency, '@mpxjs/webpack-plugin/lib/dependencies/AppEntryDependency')
|
|
57
|
+
|
|
58
|
+
module.exports = AppEntryDependency
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class CommonJsAsyncDependency extends ModuleDependency {
|
|
5
|
+
constructor (request, range) {
|
|
6
|
+
super(request)
|
|
7
|
+
this.range = range
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get type () {
|
|
11
|
+
return 'mpx cjs async'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get category () {
|
|
15
|
+
return 'commonjs'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
CommonJsAsyncDependency.Template = class CommonJsAsyncDependencyTemplate extends (
|
|
20
|
+
ModuleDependency.Template
|
|
21
|
+
) {
|
|
22
|
+
apply (
|
|
23
|
+
dep,
|
|
24
|
+
source,
|
|
25
|
+
{
|
|
26
|
+
runtimeTemplate,
|
|
27
|
+
moduleGraph,
|
|
28
|
+
chunkGraph,
|
|
29
|
+
runtimeRequirements
|
|
30
|
+
}
|
|
31
|
+
) {
|
|
32
|
+
const requireExpr = runtimeTemplate.moduleExports({
|
|
33
|
+
module: moduleGraph.getModule(dep),
|
|
34
|
+
chunkGraph,
|
|
35
|
+
request: dep.request,
|
|
36
|
+
weak: dep.weak,
|
|
37
|
+
runtimeRequirements
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const content = `Promise.resolve(${requireExpr})`
|
|
41
|
+
|
|
42
|
+
source.replace(dep.range[0], dep.range[1] - 1, content)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
makeSerializable(
|
|
47
|
+
CommonJsAsyncDependency,
|
|
48
|
+
'@mpxjs/webpack-plugin/lib/dependencies/CommonJsAsyncDependency'
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
module.exports = CommonJsAsyncDependency
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
const InitFragment = require('webpack/lib//InitFragment')
|
|
4
|
+
|
|
5
|
+
class CommonJsVariableDependency extends ModuleDependency {
|
|
6
|
+
constructor (request, name = '') {
|
|
7
|
+
super(request)
|
|
8
|
+
this.name = name
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
serialize (context) {
|
|
12
|
+
const { write } = context
|
|
13
|
+
write(this.name)
|
|
14
|
+
super.serialize(context)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
deserialize (context) {
|
|
18
|
+
const { read } = context
|
|
19
|
+
this.name = read()
|
|
20
|
+
super.deserialize(context)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
updateHash (hash, context) {
|
|
24
|
+
hash.update(this.request)
|
|
25
|
+
hash.update(this.name)
|
|
26
|
+
super.updateHash(hash, context)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get type () {
|
|
30
|
+
return 'mpx cjs variable'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get category () {
|
|
34
|
+
return 'commonjs'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate extends (
|
|
39
|
+
ModuleDependency.Template
|
|
40
|
+
) {
|
|
41
|
+
apply (
|
|
42
|
+
dep,
|
|
43
|
+
source,
|
|
44
|
+
{
|
|
45
|
+
runtimeTemplate,
|
|
46
|
+
moduleGraph,
|
|
47
|
+
chunkGraph,
|
|
48
|
+
runtimeRequirements,
|
|
49
|
+
initFragments
|
|
50
|
+
}
|
|
51
|
+
) {
|
|
52
|
+
const importedModule = moduleGraph.getModule(dep)
|
|
53
|
+
let requireExpr = runtimeTemplate.moduleExports({
|
|
54
|
+
module: importedModule,
|
|
55
|
+
chunkGraph,
|
|
56
|
+
request: dep.request,
|
|
57
|
+
weak: dep.weak,
|
|
58
|
+
runtimeRequirements
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
let expr = '/* mpx cjs variable */ '
|
|
62
|
+
if (dep.name) expr += 'var ' + dep.name + ' = '
|
|
63
|
+
expr += requireExpr + ';\n'
|
|
64
|
+
|
|
65
|
+
initFragments.push(
|
|
66
|
+
new InitFragment(
|
|
67
|
+
expr,
|
|
68
|
+
InitFragment.STAGE_CONSTANTS,
|
|
69
|
+
1,
|
|
70
|
+
dep.request
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
makeSerializable(
|
|
77
|
+
CommonJsVariableDependency,
|
|
78
|
+
'@mpxjs/webpack-plugin/lib/dependencies/CommonJsVariableDependency'
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
module.exports = CommonJsVariableDependency
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const addQuery = require('../utils/add-query')
|
|
5
|
+
const toPosix = require('../utils/to-posix')
|
|
6
|
+
const async = require('async')
|
|
7
|
+
const parseRequest = require('../utils/parse-request')
|
|
8
|
+
const { MPX_CURRENT_CHUNK } = require('../utils/const')
|
|
9
|
+
|
|
10
|
+
class DynamicEntryDependency extends NullDependency {
|
|
11
|
+
constructor (request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', range) {
|
|
12
|
+
super()
|
|
13
|
+
this.request = request
|
|
14
|
+
this.entryType = entryType
|
|
15
|
+
this.outputPath = outputPath
|
|
16
|
+
this.packageRoot = packageRoot
|
|
17
|
+
this.relativePath = relativePath
|
|
18
|
+
this.context = context
|
|
19
|
+
this.range = range
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get type () {
|
|
23
|
+
return 'mpx dynamic entry'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get key () {
|
|
27
|
+
const { request, entryType, outputPath, packageRoot, relativePath, context, range } = this
|
|
28
|
+
return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
addEntry (compilation, callback) {
|
|
32
|
+
const mpx = compilation.__mpx__
|
|
33
|
+
let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver } = this
|
|
34
|
+
|
|
35
|
+
async.waterfall([
|
|
36
|
+
(callback) => {
|
|
37
|
+
if (context && resolver) {
|
|
38
|
+
resolver.resolve({}, context, request, {}, (err, resource) => {
|
|
39
|
+
callback(err, resource)
|
|
40
|
+
})
|
|
41
|
+
} else {
|
|
42
|
+
callback(null, request)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
(resource, callback) => {
|
|
46
|
+
if (!outputPath) {
|
|
47
|
+
const { resourcePath } = parseRequest(resource)
|
|
48
|
+
outputPath = mpx.getOutputPath(resourcePath, entryType)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
|
|
52
|
+
resource,
|
|
53
|
+
outputPath,
|
|
54
|
+
resourceType: entryType,
|
|
55
|
+
warn (e) {
|
|
56
|
+
compilation.warnings.push(e)
|
|
57
|
+
},
|
|
58
|
+
error (e) {
|
|
59
|
+
compilation.errors.push(e)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
let resultPath = publicPath + filename
|
|
64
|
+
if (relativePath && relativePath !== MPX_CURRENT_CHUNK) {
|
|
65
|
+
resultPath = toPosix(path.relative(relativePath, resultPath))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// export类型的resultPath需要添加.js后缀
|
|
69
|
+
if (entryType === 'export') resultPath += '.js'
|
|
70
|
+
|
|
71
|
+
if (alreadyOutputted) return callback(null, { resultPath })
|
|
72
|
+
|
|
73
|
+
// 对于常规js模块不应添加packageRoot避免冗余
|
|
74
|
+
if (packageRoot && entryType !== 'export') {
|
|
75
|
+
resource = addQuery(resource, { packageRoot }, true)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
mpx.addEntry(resource, filename, (err, entryModule) => {
|
|
79
|
+
if (err) return callback(err)
|
|
80
|
+
if (entryType === 'export') {
|
|
81
|
+
mpx.exportModules.add(entryModule)
|
|
82
|
+
}
|
|
83
|
+
originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
84
|
+
return callback(null, {
|
|
85
|
+
resultPath,
|
|
86
|
+
entryModule
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
], callback)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
mpxAction (module, compilation, callback) {
|
|
94
|
+
const mpx = compilation.__mpx__
|
|
95
|
+
const { packageRoot, context } = this
|
|
96
|
+
this.originEntryNode = mpx.getEntryNode(module)
|
|
97
|
+
this.publicPath = compilation.outputOptions.publicPath || ''
|
|
98
|
+
if (context) this.resolver = compilation.resolverFactory.get('normal', module.resolveOptions)
|
|
99
|
+
// 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
|
|
100
|
+
if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
|
|
101
|
+
mpx.subpackagesEntriesMap[packageRoot] = mpx.subpackagesEntriesMap[packageRoot] || []
|
|
102
|
+
mpx.subpackagesEntriesMap[packageRoot].push(this)
|
|
103
|
+
callback()
|
|
104
|
+
} else {
|
|
105
|
+
this.addEntry(compilation, (err, { resultPath }) => {
|
|
106
|
+
if (err) return callback(err)
|
|
107
|
+
this.resultPath = resultPath
|
|
108
|
+
callback()
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// hash会影响最终的codeGenerateResult是否走缓存,由于该dep中resultPath是动态变更的,需要将其更新到hash中,避免错误使用缓存
|
|
114
|
+
updateHash (hash, context) {
|
|
115
|
+
const { resultPath, relativePath } = this
|
|
116
|
+
if (resultPath) hash.update(resultPath)
|
|
117
|
+
// relativePath为MPX_CURRENT_CHUNK时,插入随机hash使当前module的codeGeneration cache失效,从而执行dep.apply动态获取当前module所属的chunk路径
|
|
118
|
+
if (relativePath === MPX_CURRENT_CHUNK) hash.update('' + (+new Date()) + Math.random())
|
|
119
|
+
super.updateHash(hash, context)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
serialize (context) {
|
|
123
|
+
const { write } = context
|
|
124
|
+
write(this.request)
|
|
125
|
+
write(this.entryType)
|
|
126
|
+
write(this.outputPath)
|
|
127
|
+
write(this.packageRoot)
|
|
128
|
+
write(this.relativePath)
|
|
129
|
+
write(this.context)
|
|
130
|
+
write(this.range)
|
|
131
|
+
super.serialize(context)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
deserialize (context) {
|
|
135
|
+
const { read } = context
|
|
136
|
+
this.request = read()
|
|
137
|
+
this.entryType = read()
|
|
138
|
+
this.outputPath = read()
|
|
139
|
+
this.packageRoot = read()
|
|
140
|
+
this.relativePath = read()
|
|
141
|
+
this.context = read()
|
|
142
|
+
this.range = read()
|
|
143
|
+
super.deserialize(context)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
|
|
148
|
+
apply (dep, source, {
|
|
149
|
+
module,
|
|
150
|
+
chunkGraph
|
|
151
|
+
}) {
|
|
152
|
+
let { resultPath, range, key, outputPath, relativePath, publicPath } = dep
|
|
153
|
+
if (outputPath === 'custom-tab-bar/index') {
|
|
154
|
+
// replace with true for custom-tab-bar
|
|
155
|
+
source.replace(range[0], range[1] - 1, 'true')
|
|
156
|
+
} else if (resultPath) {
|
|
157
|
+
if (relativePath === MPX_CURRENT_CHUNK) {
|
|
158
|
+
relativePath = publicPath + path.dirname(chunkGraph.getModuleChunks(module)[0].name)
|
|
159
|
+
resultPath = toPosix(path.relative(relativePath, resultPath))
|
|
160
|
+
}
|
|
161
|
+
source.replace(range[0], range[1] - 1, JSON.stringify(resultPath))
|
|
162
|
+
} else {
|
|
163
|
+
const replaceRange = `mpx_replace_path_${key}`
|
|
164
|
+
source.replace(range[0], range[1] - 1, JSON.stringify(replaceRange))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
makeSerializable(DynamicEntryDependency, '@mpxjs/webpack-plugin/lib/dependencies/DynamicEntryDependency')
|
|
170
|
+
|
|
171
|
+
module.exports = DynamicEntryDependency
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class FlagPluginDependency extends NullDependency {
|
|
5
|
+
get type () {
|
|
6
|
+
return 'mpx flag plugin'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
mpxAction (module, compilation, callback) {
|
|
10
|
+
const mpx = compilation.__mpx__
|
|
11
|
+
mpx.isPluginMode = true
|
|
12
|
+
mpx.getEntryNode(module, 'plugin')
|
|
13
|
+
return callback()
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
FlagPluginDependency.Template = class FlagPluginDependencyTemplate {
|
|
18
|
+
apply () {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
makeSerializable(FlagPluginDependency, '@mpxjs/webpack-plugin/lib/dependencies/FlagPluginDependency')
|
|
23
|
+
|
|
24
|
+
module.exports = FlagPluginDependency
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class InjectDependency extends NullDependency {
|
|
5
|
+
constructor (options = {}) {
|
|
6
|
+
super()
|
|
7
|
+
this.content = options.content
|
|
8
|
+
this.index = options.index || 0
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get type () {
|
|
12
|
+
return 'mpx inject'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
updateHash (hash, context) {
|
|
16
|
+
hash.update(this.content)
|
|
17
|
+
super.updateHash(hash, context)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
serialize (context) {
|
|
21
|
+
const { write } = context
|
|
22
|
+
write(this.content)
|
|
23
|
+
write(this.index)
|
|
24
|
+
super.serialize(context)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deserialize (context) {
|
|
28
|
+
const { read } = context
|
|
29
|
+
this.content = read()
|
|
30
|
+
this.index = read()
|
|
31
|
+
super.deserialize(context)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
InjectDependency.Template = class InjectDependencyTemplate {
|
|
36
|
+
apply (dep, source) {
|
|
37
|
+
source.insert(dep.index, '/* mpx inject */ ' + dep.content)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
makeSerializable(InjectDependency, '@mpxjs/webpack-plugin/lib/dependencies/InjectDependency')
|
|
42
|
+
|
|
43
|
+
module.exports = InjectDependency
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
const addQuery = require('../utils/add-query')
|
|
4
|
+
|
|
5
|
+
class RecordGlobalComponentsDependency extends NullDependency {
|
|
6
|
+
constructor (usingComponents, context) {
|
|
7
|
+
super()
|
|
8
|
+
this.usingComponents = usingComponents
|
|
9
|
+
this.context = context
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get type () {
|
|
13
|
+
return 'mpx record global components'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
mpxAction (module, compilation, callback) {
|
|
17
|
+
const mpx = compilation.__mpx__
|
|
18
|
+
const { usingComponents, context } = this
|
|
19
|
+
Object.keys(usingComponents).forEach((key) => {
|
|
20
|
+
const request = usingComponents[key]
|
|
21
|
+
mpx.usingComponents[key] = addQuery(request, {
|
|
22
|
+
context
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
return callback()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
serialize (context) {
|
|
29
|
+
const { write } = context
|
|
30
|
+
write(this.usingComponents)
|
|
31
|
+
write(this.context)
|
|
32
|
+
super.serialize(context)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
deserialize (context) {
|
|
36
|
+
const { read } = context
|
|
37
|
+
this.usingComponents = read()
|
|
38
|
+
this.context = read()
|
|
39
|
+
super.deserialize(context)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
RecordGlobalComponentsDependency.Template = class RecordGlobalComponentsDependencyTemplate {
|
|
44
|
+
apply () {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
makeSerializable(RecordGlobalComponentsDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordGlobalComponentsDependency')
|
|
49
|
+
|
|
50
|
+
module.exports = RecordGlobalComponentsDependency
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class RecordIndependentDependency extends NullDependency {
|
|
5
|
+
constructor (root, request) {
|
|
6
|
+
super()
|
|
7
|
+
this.root = root
|
|
8
|
+
this.request = request
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get type () {
|
|
12
|
+
return 'mpx record independent'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
mpxAction (module, compilation, callback) {
|
|
16
|
+
const mpx = compilation.__mpx__
|
|
17
|
+
const { root, request } = this
|
|
18
|
+
mpx.independentSubpackagesMap[root] = request
|
|
19
|
+
return callback()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
serialize (context) {
|
|
23
|
+
const { write } = context
|
|
24
|
+
write(this.root)
|
|
25
|
+
write(this.request)
|
|
26
|
+
super.serialize(context)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
deserialize (context) {
|
|
30
|
+
const { read } = context
|
|
31
|
+
this.root = read()
|
|
32
|
+
this.request = read()
|
|
33
|
+
super.deserialize(context)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
RecordIndependentDependency.Template = class RecordIndependentDependencyTemplate {
|
|
38
|
+
apply () {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
makeSerializable(RecordIndependentDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordIndependentDependency')
|
|
43
|
+
|
|
44
|
+
module.exports = RecordIndependentDependency
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class RecordResourceMapDependency extends NullDependency {
|
|
5
|
+
constructor (resourcePath, resourceType, outputPath, packageRoot = '') {
|
|
6
|
+
super()
|
|
7
|
+
this.resourcePath = resourcePath
|
|
8
|
+
this.resourceType = resourceType
|
|
9
|
+
this.outputPath = outputPath
|
|
10
|
+
this.packageRoot = packageRoot
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get type () {
|
|
14
|
+
return 'mpx record resource map'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
mpxAction (module, compilation, callback) {
|
|
18
|
+
const mpx = compilation.__mpx__
|
|
19
|
+
const { resourcePath, resourceType, outputPath, packageRoot } = this
|
|
20
|
+
mpx.recordResourceMap({
|
|
21
|
+
resourcePath,
|
|
22
|
+
resourceType,
|
|
23
|
+
outputPath,
|
|
24
|
+
packageRoot,
|
|
25
|
+
recordOnly: true,
|
|
26
|
+
warn (e) {
|
|
27
|
+
compilation.warnings.push(e)
|
|
28
|
+
},
|
|
29
|
+
error (e) {
|
|
30
|
+
compilation.errors.push(e)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
return callback()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
serialize (context) {
|
|
37
|
+
const { write } = context
|
|
38
|
+
write(this.resourcePath)
|
|
39
|
+
write(this.resourceType)
|
|
40
|
+
write(this.outputPath)
|
|
41
|
+
write(this.packageRoot)
|
|
42
|
+
super.serialize(context)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
deserialize (context) {
|
|
46
|
+
const { read } = context
|
|
47
|
+
this.resourcePath = read()
|
|
48
|
+
this.resourceType = read()
|
|
49
|
+
this.outputPath = read()
|
|
50
|
+
this.packageRoot = read()
|
|
51
|
+
super.deserialize(context)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
RecordResourceMapDependency.Template = class RecordResourceMapDependencyTemplate {
|
|
56
|
+
apply () {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
makeSerializable(RecordResourceMapDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordResourceMapDependency')
|
|
61
|
+
|
|
62
|
+
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
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
2
3
|
|
|
3
4
|
class ReplaceDependency extends NullDependency {
|
|
4
5
|
constructor (replacement, range) {
|
|
@@ -11,9 +12,23 @@ class ReplaceDependency extends NullDependency {
|
|
|
11
12
|
return 'mpx replace'
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
updateHash (hash) {
|
|
15
|
-
super.updateHash(hash)
|
|
15
|
+
updateHash (hash, context) {
|
|
16
16
|
hash.update(this.replacement)
|
|
17
|
+
super.updateHash(hash, context)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
serialize (context) {
|
|
21
|
+
const { write } = context
|
|
22
|
+
write(this.replacement)
|
|
23
|
+
write(this.range)
|
|
24
|
+
super.serialize(context)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deserialize (context) {
|
|
28
|
+
const { read } = context
|
|
29
|
+
this.replacement = read()
|
|
30
|
+
this.range = read()
|
|
31
|
+
super.deserialize(context)
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
|
|
@@ -23,4 +38,6 @@ ReplaceDependency.Template = class ReplaceDependencyTemplate {
|
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
|
|
41
|
+
makeSerializable(ReplaceDependency, '@mpxjs/webpack-plugin/lib/dependencies/ReplaceDependency')
|
|
42
|
+
|
|
26
43
|
module.exports = ReplaceDependency
|