@mpxjs/webpack-plugin 2.7.0-beta.10 → 2.7.0-beta.14
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 +11 -2
- package/lib/dependencies/DynamicEntryDependency.js +3 -2
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +41 -0
- package/lib/extractor.js +4 -2
- package/lib/index.js +84 -56
- package/lib/json-compiler/index.js +2 -1
- package/lib/loader.js +28 -33
- package/lib/selector.js +21 -0
- package/lib/style-compiler/index.js +4 -5
- package/lib/template-compiler/compiler.js +4 -1
- package/lib/web/processScript.js +0 -6
- package/package.json +2 -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,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) {
|
|
@@ -44,7 +45,8 @@ 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
52
|
if (!dep.name) return
|
|
@@ -57,7 +59,14 @@ CommonJsVariableDependency.Template = class CommonJsVariableDependencyTemplate e
|
|
|
57
59
|
runtimeRequirements
|
|
58
60
|
})
|
|
59
61
|
|
|
60
|
-
|
|
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
|
+
)
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -27,7 +27,7 @@ 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
32
|
const { packageRoot, outputPath: filename, alreadyOutputed } = mpx.getPackageInfo({
|
|
33
33
|
resource,
|
|
@@ -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,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/extractor.js
CHANGED
|
@@ -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/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
|
|
|
26
26
|
const AppEntryDependency = require('./dependencies/AppEntryDependency')
|
|
27
27
|
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
28
28
|
const RecordGlobalComponentsDependency = require('./dependencies/RecordGlobalComponentsDependency')
|
|
29
|
+
const RecordIndependentDependency = require('./dependencies/RecordIndependentDependency')
|
|
29
30
|
const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
|
|
30
31
|
const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
|
|
31
32
|
const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
|
|
@@ -77,35 +78,6 @@ const isChunkInPackage = (chunkName, packageName) => {
|
|
|
77
78
|
return (new RegExp(`^${packageName}\\/`)).test(chunkName)
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
const getPackageCacheGroup = packageName => {
|
|
81
|
-
if (packageName === 'main') {
|
|
82
|
-
return {
|
|
83
|
-
// 对于独立分包模块不应用该cacheGroup
|
|
84
|
-
test: (module) => {
|
|
85
|
-
const { queryObj } = parseRequest(module.resource)
|
|
86
|
-
return !queryObj.isIndependent
|
|
87
|
-
},
|
|
88
|
-
name: 'bundle',
|
|
89
|
-
minChunks: 2,
|
|
90
|
-
chunks: 'all'
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
return {
|
|
94
|
-
test: (module, { chunkGraph }) => {
|
|
95
|
-
const chunks = chunkGraph.getModuleChunksIterable(module)
|
|
96
|
-
return chunks.size && every(chunks, (chunk) => {
|
|
97
|
-
return isChunkInPackage(chunk.name, packageName)
|
|
98
|
-
})
|
|
99
|
-
},
|
|
100
|
-
name: `${packageName}/bundle`,
|
|
101
|
-
minChunks: 2,
|
|
102
|
-
minSize: 1000,
|
|
103
|
-
priority: 100,
|
|
104
|
-
chunks: 'all'
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
81
|
const externalsMap = {
|
|
110
82
|
weui: /^weui-miniprogram/
|
|
111
83
|
}
|
|
@@ -113,20 +85,19 @@ const externalsMap = {
|
|
|
113
85
|
const warnings = []
|
|
114
86
|
const errors = []
|
|
115
87
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// }
|
|
88
|
+
class EntryNode {
|
|
89
|
+
constructor (module, type) {
|
|
90
|
+
this.module = module
|
|
91
|
+
this.type = type
|
|
92
|
+
this.parents = new Set()
|
|
93
|
+
this.children = new Set()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
addChild (node) {
|
|
97
|
+
this.children.add(node)
|
|
98
|
+
node.parents.add(this)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
130
101
|
|
|
131
102
|
class MpxWebpackPlugin {
|
|
132
103
|
constructor (options = {}) {
|
|
@@ -365,6 +336,42 @@ class MpxWebpackPlugin {
|
|
|
365
336
|
|
|
366
337
|
let mpx
|
|
367
338
|
|
|
339
|
+
const getPackageCacheGroup = packageName => {
|
|
340
|
+
if (packageName === 'main') {
|
|
341
|
+
return {
|
|
342
|
+
// 对于独立分包模块不应用该cacheGroup
|
|
343
|
+
test: (module) => {
|
|
344
|
+
let isIndependent = false
|
|
345
|
+
if (module.resource) {
|
|
346
|
+
const { queryObj } = parseRequest(module.resource)
|
|
347
|
+
isIndependent = queryObj.isIndependent
|
|
348
|
+
} else {
|
|
349
|
+
const identifier = module.identifier()
|
|
350
|
+
isIndependent = /\|isIndependent\|/.test(identifier)
|
|
351
|
+
}
|
|
352
|
+
return !isIndependent
|
|
353
|
+
},
|
|
354
|
+
name: 'bundle',
|
|
355
|
+
minChunks: 2,
|
|
356
|
+
chunks: 'all'
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
return {
|
|
360
|
+
test: (module, { chunkGraph }) => {
|
|
361
|
+
const chunks = chunkGraph.getModuleChunksIterable(module)
|
|
362
|
+
return chunks.size && every(chunks, (chunk) => {
|
|
363
|
+
return isChunkInPackage(chunk.name, packageName)
|
|
364
|
+
})
|
|
365
|
+
},
|
|
366
|
+
name: `${packageName}/bundle`,
|
|
367
|
+
minChunks: 2,
|
|
368
|
+
minSize: 1000,
|
|
369
|
+
priority: 100,
|
|
370
|
+
chunks: 'all'
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
368
375
|
const processSubpackagesEntriesMap = (compilation, callback) => {
|
|
369
376
|
const mpx = compilation.__mpx__
|
|
370
377
|
if (mpx && !isEmptyObject(mpx.subpackagesEntriesMap)) {
|
|
@@ -439,6 +446,9 @@ class MpxWebpackPlugin {
|
|
|
439
446
|
compilation.dependencyFactories.set(RecordGlobalComponentsDependency, new NullFactory())
|
|
440
447
|
compilation.dependencyTemplates.set(RecordGlobalComponentsDependency, new RecordGlobalComponentsDependency.Template())
|
|
441
448
|
|
|
449
|
+
compilation.dependencyFactories.set(RecordIndependentDependency, new NullFactory())
|
|
450
|
+
compilation.dependencyTemplates.set(RecordIndependentDependency, new RecordIndependentDependency.Template())
|
|
451
|
+
|
|
442
452
|
compilation.dependencyFactories.set(CommonJsVariableDependency, normalModuleFactory)
|
|
443
453
|
compilation.dependencyTemplates.set(CommonJsVariableDependency, new CommonJsVariableDependency.Template())
|
|
444
454
|
})
|
|
@@ -473,10 +483,8 @@ class MpxWebpackPlugin {
|
|
|
473
483
|
subpackagesEntriesMap: {},
|
|
474
484
|
replacePathMap: {},
|
|
475
485
|
exportModules: new Set(),
|
|
476
|
-
// 记录entry依赖关系,用于体积分析
|
|
477
|
-
entryNodesMap: {},
|
|
478
486
|
// 记录entryModule与entryNode的对应关系,用于体积分析
|
|
479
|
-
|
|
487
|
+
entryNodeModulesMap: new Map(),
|
|
480
488
|
extractedMap: {},
|
|
481
489
|
usingComponents: {},
|
|
482
490
|
// todo es6 map读写性能高于object,之后会逐步替换
|
|
@@ -520,6 +528,15 @@ class MpxWebpackPlugin {
|
|
|
520
528
|
compilation.addEntry(compiler.context, dep, { name }, callback)
|
|
521
529
|
return dep
|
|
522
530
|
},
|
|
531
|
+
getEntryNode: (module, type) => {
|
|
532
|
+
const entryNodeModulesMap = mpx.entryNodeModulesMap
|
|
533
|
+
let entryNode = entryNodeModulesMap.get(module)
|
|
534
|
+
if (!entryNode) {
|
|
535
|
+
entryNode = new EntryNode(module, type)
|
|
536
|
+
entryNodeModulesMap.set(module, entryNode)
|
|
537
|
+
}
|
|
538
|
+
return entryNode
|
|
539
|
+
},
|
|
523
540
|
getOutputPath: (resourcePath, type, { ext = '', conflictPath = '' } = {}) => {
|
|
524
541
|
const name = path.parse(resourcePath).name
|
|
525
542
|
const hash = mpx.pathHash(resourcePath)
|
|
@@ -672,10 +689,12 @@ class MpxWebpackPlugin {
|
|
|
672
689
|
const rawAddModule = compilation.addModule
|
|
673
690
|
compilation.addModule = (module, callback) => {
|
|
674
691
|
const issuerResource = module.issuerResource
|
|
675
|
-
|
|
676
|
-
|
|
692
|
+
const currentPackageRoot = mpx.currentPackageRoot
|
|
693
|
+
const isIndependent = mpx.independentSubpackagesMap[currentPackageRoot]
|
|
694
|
+
|
|
695
|
+
if (module.resource) {
|
|
696
|
+
// NormalModule
|
|
677
697
|
const isStatic = isStaticModule(module)
|
|
678
|
-
const isIndependent = mpx.independentSubpackagesMap[mpx.currentPackageRoot]
|
|
679
698
|
|
|
680
699
|
let needPackageQuery = isStatic || isIndependent
|
|
681
700
|
|
|
@@ -696,15 +715,24 @@ class MpxWebpackPlugin {
|
|
|
696
715
|
compilation.errors.push(e)
|
|
697
716
|
}
|
|
698
717
|
})
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
718
|
+
if (packageRoot) {
|
|
719
|
+
const queryObj = {
|
|
720
|
+
packageRoot
|
|
721
|
+
}
|
|
722
|
+
if (isIndependent) queryObj.isIndependent = true
|
|
723
|
+
module.request = addQuery(module.request, queryObj)
|
|
724
|
+
module.resource = addQuery(module.resource, queryObj)
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
} else if (isIndependent) {
|
|
728
|
+
// ContextModule和RawModule只在独立分包的情况下添加分包标记,其余默认不添加
|
|
729
|
+
const postfix = `|isIndependent|${currentPackageRoot}`
|
|
730
|
+
if (module._identifier) {
|
|
731
|
+
module._identifier += postfix
|
|
732
|
+
} else if (module.identifierStr) {
|
|
733
|
+
module.identifierStr += postfix
|
|
705
734
|
}
|
|
706
735
|
}
|
|
707
|
-
|
|
708
736
|
return rawAddModule.call(compilation, module, callback)
|
|
709
737
|
}
|
|
710
738
|
|
|
@@ -12,6 +12,7 @@ const getJSONContent = require('../utils/get-json-content')
|
|
|
12
12
|
const createHelpers = require('../helpers')
|
|
13
13
|
const createJSONHelper = require('./helper')
|
|
14
14
|
const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
|
|
15
|
+
const RecordIndependentDependency = require('../dependencies/RecordIndependentDependency')
|
|
15
16
|
const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR, JSON_JS_EXT } = require('../utils/const')
|
|
16
17
|
const resolve = require('../utils/resolve')
|
|
17
18
|
|
|
@@ -360,7 +361,7 @@ module.exports = function (content) {
|
|
|
360
361
|
const otherConfig = getOtherConfig(subPackage)
|
|
361
362
|
// 支付宝不支持独立分包,无需处理
|
|
362
363
|
if (otherConfig.independent && mode !== 'ali') {
|
|
363
|
-
|
|
364
|
+
this._module.addPresentationalDependency(new RecordIndependentDependency(tarRoot))
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
subPackagesCfg[tarRoot] = {
|
package/lib/loader.js
CHANGED
|
@@ -15,6 +15,8 @@ const getJSONContent = require('./utils/get-json-content')
|
|
|
15
15
|
const normalize = require('./utils/normalize')
|
|
16
16
|
const getEntryName = require('./utils/get-entry-name')
|
|
17
17
|
const AppEntryDependency = require('./dependencies/AppEntryDependency')
|
|
18
|
+
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
19
|
+
const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
|
|
18
20
|
const { MPX_APP_MODULE_ID } = require('./utils/const')
|
|
19
21
|
|
|
20
22
|
module.exports = function (content) {
|
|
@@ -25,7 +27,9 @@ module.exports = function (content) {
|
|
|
25
27
|
return content
|
|
26
28
|
}
|
|
27
29
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
28
|
-
const
|
|
30
|
+
const packageRoot = queryObj.packageRoot || mpx.currentPackageRoot
|
|
31
|
+
const packageName = packageRoot || 'main'
|
|
32
|
+
const isIndependent = queryObj.isIndependent
|
|
29
33
|
const pagesMap = mpx.pagesMap
|
|
30
34
|
const componentsMap = mpx.componentsMap[packageName]
|
|
31
35
|
const mode = mpx.mode
|
|
@@ -37,16 +41,6 @@ module.exports = function (content) {
|
|
|
37
41
|
const vueContentCache = mpx.vueContentCache
|
|
38
42
|
const autoScope = matchCondition(resourcePath, mpx.autoScopeRules)
|
|
39
43
|
|
|
40
|
-
// 支持资源query传入isPage或isComponent支持页面/组件单独编译
|
|
41
|
-
if ((queryObj.isComponent && !componentsMap[resourcePath]) || (queryObj.isPage && !pagesMap[resourcePath])) {
|
|
42
|
-
const entryName = getEntryName(this)
|
|
43
|
-
if (queryObj.isComponent) {
|
|
44
|
-
componentsMap[resourcePath] = entryName || 'noEntryComponent'
|
|
45
|
-
} else {
|
|
46
|
-
pagesMap[resourcePath] = entryName || 'noEntryPage'
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
let ctorType = 'app'
|
|
51
45
|
if (pagesMap[resourcePath]) {
|
|
52
46
|
// page
|
|
@@ -56,6 +50,13 @@ module.exports = function (content) {
|
|
|
56
50
|
ctorType = 'component'
|
|
57
51
|
}
|
|
58
52
|
|
|
53
|
+
// 支持资源query传入isPage或isComponent支持页面/组件单独编译
|
|
54
|
+
if (queryObj.isComponent || queryObj.isPage) {
|
|
55
|
+
const entryName = getEntryName(this) || (queryObj.isComponent ? 'noEntryComponent' : 'noEntryPage')
|
|
56
|
+
ctorType = queryObj.isComponent ? 'component' : 'page'
|
|
57
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
|
|
58
|
+
}
|
|
59
|
+
|
|
59
60
|
const loaderContext = this
|
|
60
61
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
61
62
|
const isProduction = this.minimize || process.env.NODE_ENV === 'production'
|
|
@@ -217,15 +218,21 @@ module.exports = function (content) {
|
|
|
217
218
|
if (!isProduction) {
|
|
218
219
|
output += `global.currentResource = ${JSON.stringify(filePath)}\n`
|
|
219
220
|
}
|
|
220
|
-
//
|
|
221
|
-
|
|
221
|
+
// todo 对于独立分包支持将app.mpx中的script block作为独立分包入口逻辑注入到所有页面和组件中,将独立分包i18n的注入也迁移到入口逻辑中
|
|
222
|
+
// 为app或独立分包入口注入i18n
|
|
223
|
+
if (i18n && (ctorType === 'app' || isIndependent)) {
|
|
222
224
|
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
223
225
|
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
224
226
|
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
227
|
+
const i18nMethodsVar = 'i18nMethods'
|
|
228
|
+
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest, i18nMethodsVar))
|
|
225
229
|
|
|
226
230
|
output += `if (!global.i18n) {
|
|
227
|
-
global.i18n = ${JSON.stringify({
|
|
228
|
-
|
|
231
|
+
global.i18n = ${JSON.stringify({
|
|
232
|
+
locale: i18n.locale,
|
|
233
|
+
version: 0
|
|
234
|
+
})}
|
|
235
|
+
global.i18nMethods = ${i18nMethodsVar}
|
|
229
236
|
}\n`
|
|
230
237
|
}
|
|
231
238
|
// 注入构造函数
|
|
@@ -297,29 +304,17 @@ module.exports = function (content) {
|
|
|
297
304
|
// script
|
|
298
305
|
output += '/* script */\n'
|
|
299
306
|
let scriptSrcMode = srcMode
|
|
300
|
-
|
|
307
|
+
// 给予script默认值, 确保生成js request以自动补全js
|
|
308
|
+
const script = parts.script || {}
|
|
301
309
|
if (script) {
|
|
302
310
|
scriptSrcMode = script.mode || scriptSrcMode
|
|
303
311
|
if (scriptSrcMode) output += `global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
|
|
304
|
-
|
|
312
|
+
// 传递ctorType以补全js内容
|
|
313
|
+
const extraOptions = {
|
|
314
|
+
ctorType
|
|
315
|
+
}
|
|
305
316
|
if (script.src) extraOptions.resourcePath = resourcePath
|
|
306
317
|
output += getRequire('script', script, extraOptions) + '\n'
|
|
307
|
-
} else {
|
|
308
|
-
// todo 依然创建request在selector中进行补全或者将i18n通过CommonJsVariableDependency改造为initFragments的方式进行注入,否则在app.mpx中没有script区块的情况下无法保证i18n注入代码在@mpxjs/core之前执行
|
|
309
|
-
switch (ctorType) {
|
|
310
|
-
case 'app':
|
|
311
|
-
output += 'import {createApp} from "@mpxjs/core"\n' +
|
|
312
|
-
'createApp({})\n'
|
|
313
|
-
break
|
|
314
|
-
case 'page':
|
|
315
|
-
output += 'import {createPage} from "@mpxjs/core"\n' +
|
|
316
|
-
'createPage({})\n'
|
|
317
|
-
break
|
|
318
|
-
case 'component':
|
|
319
|
-
output += 'import {createComponent} from "@mpxjs/core"\n' +
|
|
320
|
-
'createComponent({})\n'
|
|
321
|
-
}
|
|
322
|
-
output += '\n'
|
|
323
318
|
}
|
|
324
319
|
callback(null, output)
|
|
325
320
|
}
|
package/lib/selector.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = function (content) {
|
|
|
9
9
|
return content
|
|
10
10
|
}
|
|
11
11
|
const { queryObj } = parseRequest(this.resource)
|
|
12
|
+
const ctorType = queryObj.ctorType
|
|
12
13
|
const type = queryObj.type
|
|
13
14
|
const index = queryObj.index || 0
|
|
14
15
|
const mode = mpx.mode
|
|
@@ -24,6 +25,26 @@ module.exports = function (content) {
|
|
|
24
25
|
if (Array.isArray(part)) {
|
|
25
26
|
part = part[index]
|
|
26
27
|
}
|
|
28
|
+
if (!part) {
|
|
29
|
+
let content = ''
|
|
30
|
+
// 补全js内容
|
|
31
|
+
if (type === 'script') {
|
|
32
|
+
switch (ctorType) {
|
|
33
|
+
case 'app':
|
|
34
|
+
content += 'import {createApp} from "@mpxjs/core"\n' +
|
|
35
|
+
'createApp({})\n'
|
|
36
|
+
break
|
|
37
|
+
case 'page':
|
|
38
|
+
content += 'import {createPage} from "@mpxjs/core"\n' +
|
|
39
|
+
'createPage({})\n'
|
|
40
|
+
break
|
|
41
|
+
case 'component':
|
|
42
|
+
content += 'import {createComponent} from "@mpxjs/core"\n' +
|
|
43
|
+
'createComponent({})\n'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
part = { content }
|
|
47
|
+
}
|
|
27
48
|
part = part || { content: '' }
|
|
28
49
|
this.callback(null, part.content, part.map)
|
|
29
50
|
}
|
|
@@ -38,15 +38,14 @@ module.exports = function (css, map) {
|
|
|
38
38
|
},
|
|
39
39
|
config.options
|
|
40
40
|
)
|
|
41
|
-
// ali
|
|
41
|
+
// ali平台下处理scoped和host选择器
|
|
42
42
|
if (mode === 'ali') {
|
|
43
|
+
if (queryObj.scoped) {
|
|
44
|
+
plugins.push(scopeId({ id }))
|
|
45
|
+
}
|
|
43
46
|
plugins.push(transSpecial({ id }))
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
if (queryObj.scoped) {
|
|
47
|
-
plugins.push(scopeId({ id }))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
49
|
plugins.push(pluginCondStrip({
|
|
51
50
|
defs
|
|
52
51
|
}))
|
|
@@ -2039,7 +2039,10 @@ function processElement (el, root, options, meta) {
|
|
|
2039
2039
|
|
|
2040
2040
|
const pass = isNative || processTemplate(el) || processingTemplate
|
|
2041
2041
|
|
|
2042
|
-
|
|
2042
|
+
// 仅ali平台需要scoped模拟样式隔离
|
|
2043
|
+
if (mode === 'ali') {
|
|
2044
|
+
processScoped(el, options)
|
|
2045
|
+
}
|
|
2043
2046
|
|
|
2044
2047
|
if (transAli) {
|
|
2045
2048
|
processAliExternalClassesHack(el, options)
|
package/lib/web/processScript.js
CHANGED
|
@@ -113,12 +113,6 @@ module.exports = function (script, {
|
|
|
113
113
|
import Vue from 'vue'
|
|
114
114
|
import VueRouter from 'vue-router'
|
|
115
115
|
Vue.use(VueRouter)
|
|
116
|
-
import BScroll from '@better-scroll/core'
|
|
117
|
-
import PullDown from '@better-scroll/pull-down'
|
|
118
|
-
import ObserveDOM from '@better-scroll/observe-dom'
|
|
119
|
-
BScroll.use(ObserveDOM)
|
|
120
|
-
BScroll.use(PullDown)
|
|
121
|
-
global.BScroll = BScroll
|
|
122
116
|
global.getApp = function(){}
|
|
123
117
|
global.getCurrentPages = function(){
|
|
124
118
|
if(!global.__mpxRouter) return []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.0-beta.
|
|
3
|
+
"version": "2.7.0-beta.14",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"@types/babel-traverse": "^6.25.4",
|
|
78
78
|
"@types/babel-types": "^7.0.4"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "5f071c52c82077115a40350caa45669bc3b82221"
|
|
81
81
|
}
|