@mpxjs/webpack-plugin 2.7.0-alpha.0 → 2.7.0-alpha.1
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/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +13 -6
- package/lib/dependencies/DynamicEntryDependency.js +85 -41
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +11 -6
- package/lib/extractor.js +17 -7
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +6 -12
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +595 -304
- package/lib/json-compiler/helper.js +36 -32
- package/lib/json-compiler/index.js +119 -66
- package/lib/json-compiler/plugin.js +23 -7
- package/lib/loader.js +135 -90
- package/lib/native-loader.js +37 -69
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +8 -3
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +17 -5
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +4 -0
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +149 -3
- package/lib/record-loader.js +2 -2
- package/lib/resolve-loader.js +4 -1
- 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/tenon/getInnerListeners.js +317 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/components/web/getInnerListeners.js +51 -45
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +37 -8
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/runtime/optionProcessor.js +50 -20
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/runtime/stringify.wxs +6 -4
- package/lib/selector.js +23 -5
- package/lib/style-compiler/index.js +12 -13
- 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/hm.js +20 -0
- 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 +19 -12
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +172 -62
- package/lib/template-compiler/index.js +8 -9
- package/lib/template-compiler/trans-dynamic-class-expr.js +32 -22
- package/lib/tenon/index.js +105 -0
- package/lib/tenon/processJSON.js +356 -0
- package/lib/tenon/processScript.js +261 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/utils/const.js +6 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +3 -3
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -2
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +45 -38
- package/lib/web/processTemplate.js +56 -41
- package/lib/wxml/loader.js +1 -6
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxs/i18n-loader.js +5 -4
- package/lib/wxs/loader.js +87 -56
- package/lib/wxs/pre-loader.js +30 -10
- package/lib/wxss/loader.js +3 -3
- package/lib/wxss/processCss.js +135 -131
- package/package.json +23 -17
- package/lib/built-in-loader.js +0 -49
- package/lib/dependencies/RecordStaticResourceDependency.js +0 -47
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
package/README.md
CHANGED
package/lib/config.js
CHANGED
|
@@ -356,6 +356,20 @@ module.exports = {
|
|
|
356
356
|
templatePrefix: 'module.exports = \n'
|
|
357
357
|
}
|
|
358
358
|
},
|
|
359
|
+
tenon: {
|
|
360
|
+
directive: {
|
|
361
|
+
if: 'v-if',
|
|
362
|
+
elseif: 'v-else-if',
|
|
363
|
+
else: 'v-else'
|
|
364
|
+
},
|
|
365
|
+
wxs: {
|
|
366
|
+
tag: 'wxs',
|
|
367
|
+
module: 'module',
|
|
368
|
+
src: 'src',
|
|
369
|
+
ext: '.wxs',
|
|
370
|
+
templatePrefix: 'module.exports = \n'
|
|
371
|
+
}
|
|
372
|
+
},
|
|
359
373
|
qa: {
|
|
360
374
|
typeExtMap: {
|
|
361
375
|
json: '.json',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
|
|
3
|
+
class AddEntryDependency extends NullDependency {
|
|
4
|
+
constructor ({ context, dep, name }) {
|
|
5
|
+
super()
|
|
6
|
+
this.__addEntryParams = [ context, dep, name ]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get type () {
|
|
10
|
+
return 'mpx add entry'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// updateHash (hash) {
|
|
14
|
+
// super.updateHash(hash)
|
|
15
|
+
// hash.update(this.childCompileEntryModule.identifier())
|
|
16
|
+
// }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
AddEntryDependency.Template = class AddEntryDependencyTemplate {
|
|
20
|
+
apply () {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = AddEntryDependency
|
|
@@ -16,6 +16,8 @@ class AppEntryDependency extends NullDependency {
|
|
|
16
16
|
const mpx = compilation.__mpx__
|
|
17
17
|
const moduleGraph = compilation.moduleGraph
|
|
18
18
|
|
|
19
|
+
mpx.getEntryNode(module, 'app')
|
|
20
|
+
|
|
19
21
|
if (mpx.appInfo.name) {
|
|
20
22
|
const issuer = moduleGraph.getIssuer(module)
|
|
21
23
|
const err = new Error(issuer
|
|
@@ -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
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency')
|
|
2
2
|
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
const InitFragment = require('webpack/lib//InitFragment')
|
|
3
4
|
|
|
4
5
|
class CommonJsVariableDependency extends ModuleDependency {
|
|
5
|
-
constructor (request, name) {
|
|
6
|
+
constructor (request, name = '') {
|
|
6
7
|
super(request)
|
|
7
8
|
this.name = name
|
|
8
9
|
}
|
|
@@ -41,16 +42,13 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
41
42
|
dep,
|
|
42
43
|
source,
|
|
43
44
|
{
|
|
44
|
-
module,
|
|
45
45
|
runtimeTemplate,
|
|
46
46
|
moduleGraph,
|
|
47
47
|
chunkGraph,
|
|
48
48
|
runtimeRequirements,
|
|
49
|
-
runtime,
|
|
50
49
|
initFragments
|
|
51
50
|
}
|
|
52
51
|
) {
|
|
53
|
-
if (!dep.name) return
|
|
54
52
|
const importedModule = moduleGraph.getModule(dep)
|
|
55
53
|
let requireExpr = runtimeTemplate.moduleExports({
|
|
56
54
|
module: importedModule,
|
|
@@ -60,9 +58,18 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
60
58
|
runtimeRequirements
|
|
61
59
|
})
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
let expr = '/* mpx cjs variable */ '
|
|
62
|
+
if (dep.name) expr += 'var ' + dep.name + ' = '
|
|
63
|
+
expr += requireExpr + ';\n'
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
initFragments.push(
|
|
66
|
+
new InitFragment(
|
|
67
|
+
expr,
|
|
68
|
+
InitFragment.STAGE_CONSTANTS,
|
|
69
|
+
1,
|
|
70
|
+
dep.request
|
|
71
|
+
)
|
|
72
|
+
)
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
|
|
@@ -3,15 +3,19 @@ const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const addQuery = require('../utils/add-query')
|
|
5
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')
|
|
6
9
|
|
|
7
10
|
class DynamicEntryDependency extends NullDependency {
|
|
8
|
-
constructor (
|
|
11
|
+
constructor (request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', range) {
|
|
9
12
|
super()
|
|
10
|
-
this.
|
|
13
|
+
this.request = request
|
|
11
14
|
this.entryType = entryType
|
|
12
15
|
this.outputPath = outputPath
|
|
13
16
|
this.packageRoot = packageRoot
|
|
14
17
|
this.relativePath = relativePath
|
|
18
|
+
this.context = context
|
|
15
19
|
this.range = range
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -20,52 +24,78 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
get key () {
|
|
23
|
-
|
|
27
|
+
const { request, entryType, outputPath, packageRoot, relativePath, context, range } = this
|
|
28
|
+
return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
addEntry (compilation, callback) {
|
|
27
32
|
const mpx = compilation.__mpx__
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
44
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
(resource, callback) => {
|
|
46
|
+
if (!outputPath) {
|
|
47
|
+
const { resourcePath } = parseRequest(resource)
|
|
48
|
+
outputPath = mpx.getOutputPath(resourcePath, entryType)
|
|
49
|
+
}
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
})
|
|
47
62
|
|
|
48
|
-
|
|
63
|
+
let resultPath = publicPath + filename
|
|
64
|
+
if (relativePath && relativePath !== MPX_CURRENT_CHUNK) {
|
|
65
|
+
resultPath = toPosix(path.relative(relativePath, resultPath))
|
|
66
|
+
}
|
|
49
67
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
})
|
|
57
89
|
}
|
|
58
|
-
|
|
59
|
-
return callback(null, {
|
|
60
|
-
resultPath,
|
|
61
|
-
entryModule
|
|
62
|
-
})
|
|
63
|
-
})
|
|
90
|
+
], callback)
|
|
64
91
|
}
|
|
65
92
|
|
|
66
93
|
mpxAction (module, compilation, callback) {
|
|
67
94
|
const mpx = compilation.__mpx__
|
|
68
|
-
const { packageRoot } = this
|
|
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)
|
|
69
99
|
// 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
|
|
70
100
|
if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
|
|
71
101
|
mpx.subpackagesEntriesMap[packageRoot] = mpx.subpackagesEntriesMap[packageRoot] || []
|
|
@@ -82,38 +112,52 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
82
112
|
|
|
83
113
|
// hash会影响最终的codeGenerateResult是否走缓存,由于该dep中resultPath是动态变更的,需要将其更新到hash中,避免错误使用缓存
|
|
84
114
|
updateHash (hash, context) {
|
|
85
|
-
const { resultPath } = this
|
|
115
|
+
const { resultPath, relativePath } = this
|
|
86
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())
|
|
87
119
|
super.updateHash(hash, context)
|
|
88
120
|
}
|
|
89
121
|
|
|
90
122
|
serialize (context) {
|
|
91
123
|
const { write } = context
|
|
92
|
-
write(this.
|
|
124
|
+
write(this.request)
|
|
93
125
|
write(this.entryType)
|
|
94
126
|
write(this.outputPath)
|
|
95
127
|
write(this.packageRoot)
|
|
96
128
|
write(this.relativePath)
|
|
129
|
+
write(this.context)
|
|
97
130
|
write(this.range)
|
|
98
131
|
super.serialize(context)
|
|
99
132
|
}
|
|
100
133
|
|
|
101
134
|
deserialize (context) {
|
|
102
135
|
const { read } = context
|
|
103
|
-
this.
|
|
136
|
+
this.request = read()
|
|
104
137
|
this.entryType = read()
|
|
105
138
|
this.outputPath = read()
|
|
106
139
|
this.packageRoot = read()
|
|
107
140
|
this.relativePath = read()
|
|
141
|
+
this.context = read()
|
|
108
142
|
this.range = read()
|
|
109
143
|
super.deserialize(context)
|
|
110
144
|
}
|
|
111
145
|
}
|
|
112
146
|
|
|
113
147
|
DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
|
|
114
|
-
apply (dep, source
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}
|
|
117
161
|
source.replace(range[0], range[1] - 1, JSON.stringify(resultPath))
|
|
118
162
|
} else {
|
|
119
163
|
const replaceRange = `mpx_replace_path_${key}`
|
|
@@ -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
|
|
@@ -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,11 +73,11 @@ 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
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
78
|
+
// for tenon
|
|
79
|
+
if (dep.compilation.__mpx__.mode === 'tenon') {
|
|
80
|
+
return `getRelativePath(currentURL, ${JSON.stringify(resolved)}) + '.js'`
|
|
76
81
|
}
|
|
77
82
|
return JSON.stringify(publicPath + resolved)
|
|
78
83
|
}
|
package/lib/extractor.js
CHANGED
|
@@ -3,8 +3,8 @@ 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')
|
|
7
|
+
const normalize = require('./utils/normalize')
|
|
8
8
|
const { MPX_DISABLE_EXTRACTOR_CACHE, DEFAULT_RESULT_SOURCE } = require('./utils/const')
|
|
9
9
|
|
|
10
10
|
module.exports = content => content
|
|
@@ -16,7 +16,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
16
16
|
const type = queryObj.type
|
|
17
17
|
const index = queryObj.index || 0
|
|
18
18
|
const isStatic = queryObj.isStatic
|
|
19
|
-
const
|
|
19
|
+
const issuerResource = queryObj.issuerResource
|
|
20
20
|
const fromImport = queryObj.fromImport
|
|
21
21
|
const needBabel = queryObj.needBabel
|
|
22
22
|
|
|
@@ -36,8 +36,13 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
36
36
|
}
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
+
if (issuerResource) {
|
|
40
|
+
// 清空issuerResource/index query避免importModule对于不同的issuer无法复用模块缓存
|
|
41
|
+
remainingRequest = addQuery(remainingRequest, {}, false, ['issuerResource', 'index'])
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
let request = remainingRequest
|
|
40
|
-
// static
|
|
45
|
+
// static的情况下需要用record-loader记录相关静态资源的输出路径,不能直接在这里记录,需要确保在子依赖开始构建前完成记录,因为子依赖构建时可能就需要访问当前资源的输出路径
|
|
41
46
|
if (isStatic) {
|
|
42
47
|
const recordLoader = normalize.lib('record-loader')
|
|
43
48
|
request = `${recordLoader}!${remainingRequest}`
|
|
@@ -51,6 +56,10 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
51
56
|
}).join('\n')
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
let resultSource = DEFAULT_RESULT_SOURCE
|
|
60
|
+
|
|
61
|
+
if (typeof content !== 'string') return resultSource
|
|
62
|
+
|
|
54
63
|
const extractedInfo = {
|
|
55
64
|
content,
|
|
56
65
|
index
|
|
@@ -61,8 +70,6 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
61
70
|
extractedInfo
|
|
62
71
|
})
|
|
63
72
|
|
|
64
|
-
let resultSource = DEFAULT_RESULT_SOURCE
|
|
65
|
-
|
|
66
73
|
const { buildInfo } = this._module
|
|
67
74
|
|
|
68
75
|
// 如果importModule子模块中包含动态特性,比如动态添加入口和静态资源输出路径,则当前extractor模块不可缓存
|
|
@@ -80,16 +87,19 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
80
87
|
// styles为static就两种情况,一种是.mpx中使用src引用样式,第二种为css-loader中处理@import
|
|
81
88
|
// 为了支持持久化缓存,.mpx中使用src引用样式对issueFile asset产生的副作用迁移到ExtractDependency中处理
|
|
82
89
|
case 'styles':
|
|
83
|
-
if (
|
|
90
|
+
if (issuerResource) {
|
|
91
|
+
const issuerFile = mpx.getExtractedFile(issuerResource)
|
|
84
92
|
let relativePath = toPosix(path.relative(path.dirname(issuerFile), file))
|
|
85
93
|
relativePath = fixRelative(relativePath, mode)
|
|
86
94
|
if (fromImport) {
|
|
87
95
|
resultSource += `module.exports = ${JSON.stringify(relativePath)};\n`
|
|
88
96
|
} else {
|
|
89
97
|
this.emitFile(issuerFile, '', undefined, {
|
|
98
|
+
skipEmit: true,
|
|
90
99
|
extractedInfo: {
|
|
91
100
|
content: `@import "${relativePath}";\n`,
|
|
92
|
-
index
|
|
101
|
+
index,
|
|
102
|
+
pre: true
|
|
93
103
|
}
|
|
94
104
|
})
|
|
95
105
|
}
|
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)}`
|