@mpxjs/webpack-plugin 2.7.0-beta.0 → 2.7.0-beta.12
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/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsVariableDependency.js +9 -5
- package/lib/dependencies/DynamicEntryDependency.js +8 -3
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +41 -0
- 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 +7 -4
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +1 -0
- package/lib/index.js +227 -151
- package/lib/json-compiler/helper.js +21 -25
- package/lib/json-compiler/index.js +70 -54
- package/lib/json-compiler/plugin.js +21 -5
- package/lib/loader.js +59 -77
- 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/record-loader.js +2 -2
- 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 +23 -5
- 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 -30
- 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/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
|
@@ -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
|
|
@@ -1,5 +1,6 @@
|
|
|
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
6
|
constructor (request, name) {
|
|
@@ -41,12 +42,10 @@ 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
|
) {
|
|
@@ -60,9 +59,14 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
60
59
|
runtimeRequirements
|
|
61
60
|
})
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
initFragments.push(
|
|
63
|
+
new InitFragment(
|
|
64
|
+
`/* mpx cjs variable */ var ${dep.name} = ${requireExpr};\n`,
|
|
65
|
+
InitFragment.STAGE_CONSTANTS,
|
|
66
|
+
1,
|
|
67
|
+
`mpx cjs variable ${dep.name}`
|
|
68
|
+
)
|
|
69
|
+
)
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -20,13 +20,14 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
get key () {
|
|
23
|
-
|
|
23
|
+
const { resource, entryType, outputPath, packageRoot, relativePath, range } = this
|
|
24
|
+
return toPosix([resource, entryType, outputPath, packageRoot, relativePath, ...range].join('|'))
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
addEntry (compilation, callback) {
|
|
27
28
|
const mpx = compilation.__mpx__
|
|
28
29
|
const publicPath = compilation.outputOptions.publicPath || ''
|
|
29
|
-
let { resource, entryType, outputPath, relativePath } = this
|
|
30
|
+
let { resource, entryType, outputPath, relativePath, originEntryNode } = this
|
|
30
31
|
|
|
31
32
|
const { packageRoot, outputPath: filename, alreadyOutputed } = mpx.getPackageInfo({
|
|
32
33
|
resource,
|
|
@@ -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) {
|
|
@@ -55,7 +59,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
55
59
|
if (entryType === 'export') {
|
|
56
60
|
mpx.exportModules.add(entryModule)
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
59
63
|
return callback(null, {
|
|
60
64
|
resultPath,
|
|
61
65
|
entryModule
|
|
@@ -66,6 +70,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
66
70
|
mpxAction (module, compilation, callback) {
|
|
67
71
|
const mpx = compilation.__mpx__
|
|
68
72
|
const { packageRoot } = this
|
|
73
|
+
this.originEntryNode = mpx.getEntryNode(module)
|
|
69
74
|
// 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
|
|
70
75
|
if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
|
|
71
76
|
mpx.subpackagesEntriesMap[packageRoot] = mpx.subpackagesEntriesMap[packageRoot] || []
|
|
@@ -0,0 +1,41 @@
|
|
|
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) {
|
|
6
|
+
super()
|
|
7
|
+
this.root = root
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get type () {
|
|
11
|
+
return 'mpx record independent'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mpxAction (module, compilation, callback) {
|
|
15
|
+
const mpx = compilation.__mpx__
|
|
16
|
+
const { root } = this
|
|
17
|
+
mpx.independentSubpackagesMap[root] = true
|
|
18
|
+
return callback()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
serialize (context) {
|
|
22
|
+
const { write } = context
|
|
23
|
+
write(this.root)
|
|
24
|
+
super.serialize(context)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deserialize (context) {
|
|
28
|
+
const { read } = context
|
|
29
|
+
this.root = read()
|
|
30
|
+
super.deserialize(context)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
RecordIndependentDependency.Template = class RecordIndependentDependencyTemplate {
|
|
35
|
+
apply () {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
makeSerializable(RecordIndependentDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordIndependentDependency')
|
|
40
|
+
|
|
41
|
+
module.exports = RecordIndependentDependency
|
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,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
|
|
@@ -37,7 +37,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
let request = remainingRequest
|
|
40
|
-
// static
|
|
40
|
+
// static的情况下需要用record-loader记录相关静态资源的输出路径,不能直接在这里记录,需要确保在子依赖开始构建前完成记录,因为子依赖构建时可能就需要访问当前资源的输出路径
|
|
41
41
|
if (isStatic) {
|
|
42
42
|
const recordLoader = normalize.lib('record-loader')
|
|
43
43
|
request = `${recordLoader}!${remainingRequest}`
|
|
@@ -51,6 +51,10 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
51
51
|
}).join('\n')
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
let resultSource = DEFAULT_RESULT_SOURCE
|
|
55
|
+
|
|
56
|
+
if (typeof content !== 'string') return resultSource
|
|
57
|
+
|
|
54
58
|
const extractedInfo = {
|
|
55
59
|
content,
|
|
56
60
|
index
|
|
@@ -61,8 +65,6 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
61
65
|
extractedInfo
|
|
62
66
|
})
|
|
63
67
|
|
|
64
|
-
let resultSource = DEFAULT_RESULT_SOURCE
|
|
65
|
-
|
|
66
68
|
const { buildInfo } = this._module
|
|
67
69
|
|
|
68
70
|
// 如果importModule子模块中包含动态特性,比如动态添加入口和静态资源输出路径,则当前extractor模块不可缓存
|
|
@@ -87,6 +89,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
87
89
|
resultSource += `module.exports = ${JSON.stringify(relativePath)};\n`
|
|
88
90
|
} else {
|
|
89
91
|
this.emitFile(issuerFile, '', undefined, {
|
|
92
|
+
skipEmit: true,
|
|
90
93
|
extractedInfo: {
|
|
91
94
|
content: `@import "${relativePath}";\n`,
|
|
92
95
|
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