@mpxjs/webpack-plugin 2.7.0-beta.1 → 2.7.0-beta.10
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 +3 -2
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +1 -0
- package/lib/index.js +171 -127
- package/lib/json-compiler/helper.js +21 -25
- package/lib/json-compiler/index.js +68 -53
- package/lib/json-compiler/plugin.js +21 -5
- package/lib/loader.js +42 -54
- 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 +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/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 toPosix([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,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}`
|
|
@@ -87,6 +87,7 @@ module.exports.pitch = async function (remainingRequest) {
|
|
|
87
87
|
resultSource += `module.exports = ${JSON.stringify(relativePath)};\n`
|
|
88
88
|
} else {
|
|
89
89
|
this.emitFile(issuerFile, '', undefined, {
|
|
90
|
+
skipEmit: true,
|
|
90
91
|
extractedInfo: {
|
|
91
92
|
content: `@import "${relativePath}";\n`,
|
|
92
93
|
index: -1
|
package/lib/file-loader.js
CHANGED
|
@@ -2,7 +2,7 @@ const path = require('path')
|
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const toPosix = require('./utils/to-posix')
|
|
4
4
|
const parseRequest = require('./utils/parse-request')
|
|
5
|
-
const
|
|
5
|
+
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
6
6
|
|
|
7
7
|
module.exports = function loader (content, prevOptions) {
|
|
8
8
|
const options = prevOptions || loaderUtils.getOptions(this) || {}
|
|
@@ -28,7 +28,7 @@ module.exports = function loader (content, prevOptions) {
|
|
|
28
28
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
29
29
|
const packageRoot = queryObj.packageRoot || ''
|
|
30
30
|
url = outputPath = toPosix(path.join(packageRoot, outputPath))
|
|
31
|
-
this._module.addPresentationalDependency(new
|
|
31
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot))
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}`
|
package/lib/helpers.js
CHANGED