@mpxjs/webpack-plugin 2.7.0-beta.9 → 2.7.1-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/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsVariableDependency.js +16 -4
- package/lib/dependencies/DynamicEntryDependency.js +5 -4
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +13 -4
- package/lib/extractor.js +8 -6
- package/lib/helpers.js +5 -12
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +217 -96
- package/lib/json-compiler/index.js +39 -10
- package/lib/loader.js +56 -48
- package/lib/native-loader.js +4 -3
- package/lib/record-loader.js +11 -0
- package/lib/runtime/components/web/mpx-swiper.vue +19 -5
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/runtime/stringify.wxs +3 -1
- package/lib/selector.js +21 -0
- package/lib/style-compiler/index.js +6 -6
- package/lib/style-compiler/plugins/vw.js +5 -4
- package/lib/template-compiler/compiler.js +7 -2
- package/lib/template-compiler/index.js +2 -1
- package/lib/template-compiler/trans-dynamic-class-expr.js +25 -20
- package/lib/web/processJSON.js +1 -1
- package/lib/web/processScript.js +2 -8
- package/lib/web/processTemplate.js +1 -1
- package/lib/wxs/i18n-loader.js +4 -1
- package/lib/wxs/pre-loader.js +6 -1
- package/package.json +5 -2
|
@@ -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,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
|
}
|
|
@@ -44,10 +45,10 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
44
45
|
runtimeTemplate,
|
|
45
46
|
moduleGraph,
|
|
46
47
|
chunkGraph,
|
|
47
|
-
runtimeRequirements
|
|
48
|
+
runtimeRequirements,
|
|
49
|
+
initFragments
|
|
48
50
|
}
|
|
49
51
|
) {
|
|
50
|
-
if (!dep.name) return
|
|
51
52
|
const importedModule = moduleGraph.getModule(dep)
|
|
52
53
|
let requireExpr = runtimeTemplate.moduleExports({
|
|
53
54
|
module: importedModule,
|
|
@@ -57,7 +58,18 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
57
58
|
runtimeRequirements
|
|
58
59
|
})
|
|
59
60
|
|
|
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
|
+
)
|
|
61
73
|
}
|
|
62
74
|
}
|
|
63
75
|
|
|
@@ -27,9 +27,9 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
27
27
|
addEntry (compilation, callback) {
|
|
28
28
|
const mpx = compilation.__mpx__
|
|
29
29
|
const publicPath = compilation.outputOptions.publicPath || ''
|
|
30
|
-
let { resource, entryType, outputPath, relativePath } = this
|
|
30
|
+
let { resource, entryType, outputPath, relativePath, originEntryNode } = this
|
|
31
31
|
|
|
32
|
-
const { packageRoot, outputPath: filename,
|
|
32
|
+
const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
|
|
33
33
|
resource,
|
|
34
34
|
outputPath,
|
|
35
35
|
resourceType: entryType,
|
|
@@ -49,7 +49,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
49
49
|
// export类型的resultPath需要添加.js后缀
|
|
50
50
|
if (entryType === 'export') resultPath += '.js'
|
|
51
51
|
|
|
52
|
-
if (
|
|
52
|
+
if (alreadyOutputted) return callback(null, { resultPath })
|
|
53
53
|
|
|
54
54
|
if (packageRoot) {
|
|
55
55
|
resource = addQuery(resource, { packageRoot })
|
|
@@ -59,7 +59,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
59
59
|
if (entryType === 'export') {
|
|
60
60
|
mpx.exportModules.add(entryModule)
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
|
|
63
63
|
return callback(null, {
|
|
64
64
|
resultPath,
|
|
65
65
|
entryModule
|
|
@@ -70,6 +70,7 @@ class DynamicEntryDependency extends NullDependency {
|
|
|
70
70
|
mpxAction (module, compilation, callback) {
|
|
71
71
|
const mpx = compilation.__mpx__
|
|
72
72
|
const { packageRoot } = this
|
|
73
|
+
this.originEntryNode = mpx.getEntryNode(module)
|
|
73
74
|
// 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
|
|
74
75
|
if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
|
|
75
76
|
mpx.subpackagesEntriesMap[packageRoot] = mpx.subpackagesEntriesMap[packageRoot] || []
|
|
@@ -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
|
|
@@ -16,10 +16,19 @@ class RecordResourceMapDependency extends NullDependency {
|
|
|
16
16
|
|
|
17
17
|
mpxAction (module, compilation, callback) {
|
|
18
18
|
const mpx = compilation.__mpx__
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const { resourcePath, resourceType, outputPath, packageRoot } = this
|
|
20
|
+
mpx.recordResourceMap({
|
|
21
|
+
resourcePath,
|
|
22
|
+
resourceType,
|
|
23
|
+
outputPath,
|
|
24
|
+
packageRoot,
|
|
25
|
+
warn (e) {
|
|
26
|
+
compilation.warnings.push(e)
|
|
27
|
+
},
|
|
28
|
+
error (e) {
|
|
29
|
+
compilation.errors.push(e)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
23
32
|
return callback()
|
|
24
33
|
}
|
|
25
34
|
|
package/lib/extractor.js
CHANGED
|
@@ -4,8 +4,8 @@ const parseRequest = require('./utils/parse-request')
|
|
|
4
4
|
const toPosix = require('./utils/to-posix')
|
|
5
5
|
const fixRelative = require('./utils/fix-relative')
|
|
6
6
|
const addQuery = require('./utils/add-query')
|
|
7
|
+
const normalize = require('./utils/normalize')
|
|
7
8
|
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的情况下需要用record-loader记录相关静态资源的输出路径,不能直接在这里记录,需要确保在子依赖开始构建前完成记录,因为子依赖构建时可能就需要访问当前资源的输出路径
|
|
41
41
|
if (isStatic) {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const recordLoader = normalize.lib('record-loader')
|
|
43
|
+
request = `${recordLoader}!${remainingRequest}`
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let content = await this.importModule(`!!${request}`)
|
|
@@ -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模块不可缓存
|
package/lib/helpers.js
CHANGED
|
@@ -4,14 +4,6 @@ const selectorPath = normalize.lib('selector')
|
|
|
4
4
|
const addQuery = require('./utils/add-query')
|
|
5
5
|
const parseRequest = require('./utils/parse-request')
|
|
6
6
|
|
|
7
|
-
function getRawRequest ({ resource, loaderIndex, loaders }, excludedPreLoaders = /eslint-loader/) {
|
|
8
|
-
return loaderUtils.getRemainingRequest({
|
|
9
|
-
resource: resource,
|
|
10
|
-
loaderIndex: loaderIndex,
|
|
11
|
-
loaders: loaders.filter(loader => !excludedPreLoaders.test(loader.path))
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
7
|
const defaultLang = {
|
|
16
8
|
template: 'wxml',
|
|
17
9
|
styles: 'wxss',
|
|
@@ -21,7 +13,8 @@ const defaultLang = {
|
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
module.exports = function createHelpers (loaderContext) {
|
|
24
|
-
const rawRequest =
|
|
16
|
+
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
25
18
|
|
|
26
19
|
function getRequire (type, part, extraOptions, index) {
|
|
27
20
|
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
@@ -43,9 +36,9 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
43
36
|
|
|
44
37
|
function getFakeRequest (type, part) {
|
|
45
38
|
const lang = part.lang || defaultLang[type] || type
|
|
46
|
-
const {
|
|
47
|
-
if (lang === 'json')
|
|
48
|
-
return addQuery(`${resourcePath}.${lang}`,
|
|
39
|
+
const options = { ...queryObj }
|
|
40
|
+
if (lang === 'json') options.asScript = true
|
|
41
|
+
return addQuery(`${resourcePath}.${lang}`, options)
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
function getRequestString (type, part, extraOptions = {}, index = 0) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const parseComponent = require('./parser')
|
|
2
|
+
const createHelpers = require('./helpers')
|
|
3
|
+
const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const normalize = require('./utils/normalize')
|
|
6
|
+
|
|
7
|
+
module.exports = function (content) {
|
|
8
|
+
this.cacheable()
|
|
9
|
+
const mpx = this.getMpx()
|
|
10
|
+
if (!mpx) {
|
|
11
|
+
return content
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const mode = mpx.mode
|
|
15
|
+
const env = mpx.env
|
|
16
|
+
const i18n = mpx.i18n
|
|
17
|
+
const filePath = this.resourcePath
|
|
18
|
+
const extname = path.extname(filePath)
|
|
19
|
+
if (extname === '.mpx') {
|
|
20
|
+
const parts = parseComponent(content, {
|
|
21
|
+
filePath,
|
|
22
|
+
needMap: this.sourceMap,
|
|
23
|
+
mode,
|
|
24
|
+
env
|
|
25
|
+
})
|
|
26
|
+
const {
|
|
27
|
+
getRequire
|
|
28
|
+
} = createHelpers(this)
|
|
29
|
+
|
|
30
|
+
if (parts.script) {
|
|
31
|
+
content = getRequire('script', parts.script)
|
|
32
|
+
} else {
|
|
33
|
+
content = ''
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let output = 'global.isIndependent = true\n'
|
|
38
|
+
// 注入i18n
|
|
39
|
+
if (i18n) {
|
|
40
|
+
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
41
|
+
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
42
|
+
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
43
|
+
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
44
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
45
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
46
|
+
}
|
|
47
|
+
output += content
|
|
48
|
+
output += '\n'
|
|
49
|
+
output += 'delete global.isIndependent\n'
|
|
50
|
+
|
|
51
|
+
return output
|
|
52
|
+
}
|