@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115

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.
Files changed (129) hide show
  1. package/README.md +1 -1
  2. package/lib/built-in-loader.js +49 -0
  3. package/lib/config.js +0 -14
  4. package/lib/content-loader.js +13 -0
  5. package/lib/dependency/ChildCompileDependency.js +24 -0
  6. package/lib/dependency/InjectDependency.js +26 -0
  7. package/lib/dependency/RemovedModuleDependency.js +23 -0
  8. package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
  9. package/lib/dependency/ResolveDependency.js +49 -0
  10. package/lib/extractor.js +178 -82
  11. package/lib/file-loader.js +19 -7
  12. package/lib/helpers.js +334 -39
  13. package/lib/index.js +525 -889
  14. package/lib/json-compiler/index.js +451 -245
  15. package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
  16. package/lib/loader.js +241 -178
  17. package/lib/native-loader.js +133 -71
  18. package/lib/parser.js +2 -1
  19. package/lib/path-loader.js +3 -0
  20. package/lib/platform/json/wx/index.js +1 -1
  21. package/lib/platform/template/normalize-component-rules.js +3 -2
  22. package/lib/platform/template/wx/component-config/button.js +2 -14
  23. package/lib/platform/template/wx/component-config/image.js +0 -4
  24. package/lib/platform/template/wx/component-config/input.js +0 -4
  25. package/lib/platform/template/wx/component-config/rich-text.js +0 -4
  26. package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
  27. package/lib/platform/template/wx/component-config/switch.js +0 -4
  28. package/lib/platform/template/wx/component-config/text.js +0 -4
  29. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  30. package/lib/platform/template/wx/component-config/view.js +0 -4
  31. package/lib/platform/template/wx/index.js +3 -149
  32. package/lib/plugin-loader.js +287 -0
  33. package/lib/resolver/AddEnvPlugin.js +3 -4
  34. package/lib/resolver/AddModePlugin.js +3 -4
  35. package/lib/resolver/PackageEntryPlugin.js +36 -23
  36. package/lib/runtime/base.styl +0 -5
  37. package/lib/runtime/components/web/getInnerListeners.js +3 -1
  38. package/lib/runtime/components/web/mpx-image.vue +5 -20
  39. package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
  40. package/lib/runtime/components/web/mpx-swiper.vue +3 -18
  41. package/lib/runtime/i18n.wxs +11 -31
  42. package/lib/runtime/optionProcessor.js +3 -48
  43. package/lib/selector.js +10 -29
  44. package/lib/staticConfig.js +4 -0
  45. package/lib/style-compiler/index.js +24 -16
  46. package/lib/style-compiler/load-postcss-config.js +1 -3
  47. package/lib/style-compiler/plugins/conditional-strip.js +65 -68
  48. package/lib/style-compiler/plugins/rpx.js +37 -43
  49. package/lib/style-compiler/plugins/scope-id.js +72 -79
  50. package/lib/style-compiler/plugins/trans-special.js +18 -25
  51. package/lib/style-compiler/plugins/trim.js +7 -13
  52. package/lib/style-compiler/plugins/vw.js +16 -22
  53. package/lib/template-compiler/compiler.js +199 -106
  54. package/lib/template-compiler/index.js +139 -52
  55. package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
  56. package/lib/url-loader.js +29 -11
  57. package/lib/utils/add-query.js +1 -1
  58. package/lib/utils/get-main-compilation.js +6 -0
  59. package/lib/utils/is-url-request.js +1 -10
  60. package/lib/utils/match-condition.js +1 -4
  61. package/lib/utils/normalize.js +15 -4
  62. package/lib/utils/parse-request.js +3 -3
  63. package/lib/utils/read-json-for-src.js +34 -0
  64. package/lib/utils/stringify-query.js +0 -4
  65. package/lib/utils/try-require.js +16 -0
  66. package/lib/web/processJSON.js +144 -113
  67. package/lib/web/processScript.js +34 -47
  68. package/lib/web/processTemplate.js +40 -57
  69. package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
  70. package/lib/wxs/WxsParserPlugin.js +2 -2
  71. package/lib/wxs/WxsPlugin.js +8 -4
  72. package/lib/wxs/WxsTemplatePlugin.js +92 -46
  73. package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
  74. package/lib/wxs/wxs-loader.js +117 -0
  75. package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
  76. package/lib/wxss/getImportPrefix.js +30 -0
  77. package/lib/wxss/loader.js +43 -31
  78. package/lib/wxss/localsLoader.js +5 -1
  79. package/lib/wxss/processCss.js +103 -107
  80. package/package.json +18 -21
  81. package/LICENSE +0 -433
  82. package/lib/dependencies/AddEntryDependency.js +0 -24
  83. package/lib/dependencies/AppEntryDependency.js +0 -58
  84. package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
  85. package/lib/dependencies/CommonJsVariableDependency.js +0 -81
  86. package/lib/dependencies/DynamicEntryDependency.js +0 -171
  87. package/lib/dependencies/FlagPluginDependency.js +0 -24
  88. package/lib/dependencies/InjectDependency.js +0 -43
  89. package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
  90. package/lib/dependencies/RecordIndependentDependency.js +0 -44
  91. package/lib/dependencies/RecordResourceMapDependency.js +0 -62
  92. package/lib/dependencies/RemoveEntryDependency.js +0 -40
  93. package/lib/dependencies/ResolveDependency.js +0 -88
  94. package/lib/independent-loader.js +0 -52
  95. package/lib/json-compiler/helper.js +0 -156
  96. package/lib/json-compiler/plugin.js +0 -150
  97. package/lib/partial-compile/index.js +0 -35
  98. package/lib/record-loader.js +0 -11
  99. package/lib/resolve-loader.js +0 -6
  100. package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
  101. package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
  102. package/lib/runtime/components/tenon/tenon-button.vue +0 -305
  103. package/lib/runtime/components/tenon/tenon-image.vue +0 -61
  104. package/lib/runtime/components/tenon/tenon-input.vue +0 -99
  105. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
  106. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
  107. package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
  108. package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
  109. package/lib/runtime/components/tenon/tenon-text.vue +0 -64
  110. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  111. package/lib/runtime/components/tenon/util.js +0 -44
  112. package/lib/runtime/optionProcessor.tenon.js +0 -386
  113. package/lib/style-compiler/plugins/hm.js +0 -20
  114. package/lib/tenon/index.js +0 -105
  115. package/lib/tenon/processJSON.js +0 -360
  116. package/lib/tenon/processScript.js +0 -260
  117. package/lib/tenon/processStyles.js +0 -21
  118. package/lib/tenon/processTemplate.js +0 -133
  119. package/lib/utils/const.js +0 -10
  120. package/lib/utils/emit-file.js +0 -10
  121. package/lib/utils/eval-json-js.js +0 -31
  122. package/lib/utils/get-entry-name.js +0 -13
  123. package/lib/utils/get-json-content.js +0 -42
  124. package/lib/utils/get-relative-path.js +0 -24
  125. package/lib/utils/resolve.js +0 -13
  126. package/lib/utils/set.js +0 -47
  127. package/lib/utils/stringify-loaders-resource.js +0 -25
  128. package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
  129. package/lib/wxs/loader.js +0 -142
@@ -1,171 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const makeSerializable = require('webpack/lib/util/makeSerializable')
3
- const path = require('path')
4
- const addQuery = require('../utils/add-query')
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')
9
-
10
- class DynamicEntryDependency extends NullDependency {
11
- constructor (request, entryType, outputPath = '', packageRoot = '', relativePath = '', context = '', range) {
12
- super()
13
- this.request = request
14
- this.entryType = entryType
15
- this.outputPath = outputPath
16
- this.packageRoot = packageRoot
17
- this.relativePath = relativePath
18
- this.context = context
19
- this.range = range
20
- }
21
-
22
- get type () {
23
- return 'mpx dynamic entry'
24
- }
25
-
26
- get key () {
27
- const { request, entryType, outputPath, packageRoot, relativePath, context, range } = this
28
- return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
29
- }
30
-
31
- addEntry (compilation, callback) {
32
- const mpx = compilation.__mpx__
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
- }
44
- },
45
- (resource, callback) => {
46
- if (!outputPath) {
47
- const { resourcePath } = parseRequest(resource)
48
- outputPath = mpx.getOutputPath(resourcePath, entryType)
49
- }
50
-
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
- })
62
-
63
- let resultPath = publicPath + filename
64
- if (relativePath && relativePath !== MPX_CURRENT_CHUNK) {
65
- resultPath = toPosix(path.relative(relativePath, resultPath))
66
- }
67
-
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
- })
89
- }
90
- ], callback)
91
- }
92
-
93
- mpxAction (module, compilation, callback) {
94
- const mpx = compilation.__mpx__
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)
99
- // 分包构建在需要在主包构建完成后在finishMake中处理,返回的资源路径先用key来占位,在合成extractedAssets时再进行最终替换
100
- if (packageRoot && mpx.currentPackageRoot !== packageRoot) {
101
- mpx.subpackagesEntriesMap[packageRoot] = mpx.subpackagesEntriesMap[packageRoot] || []
102
- mpx.subpackagesEntriesMap[packageRoot].push(this)
103
- callback()
104
- } else {
105
- this.addEntry(compilation, (err, { resultPath }) => {
106
- if (err) return callback(err)
107
- this.resultPath = resultPath
108
- callback()
109
- })
110
- }
111
- }
112
-
113
- // hash会影响最终的codeGenerateResult是否走缓存,由于该dep中resultPath是动态变更的,需要将其更新到hash中,避免错误使用缓存
114
- updateHash (hash, context) {
115
- const { resultPath, relativePath } = this
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())
119
- super.updateHash(hash, context)
120
- }
121
-
122
- serialize (context) {
123
- const { write } = context
124
- write(this.request)
125
- write(this.entryType)
126
- write(this.outputPath)
127
- write(this.packageRoot)
128
- write(this.relativePath)
129
- write(this.context)
130
- write(this.range)
131
- super.serialize(context)
132
- }
133
-
134
- deserialize (context) {
135
- const { read } = context
136
- this.request = read()
137
- this.entryType = read()
138
- this.outputPath = read()
139
- this.packageRoot = read()
140
- this.relativePath = read()
141
- this.context = read()
142
- this.range = read()
143
- super.deserialize(context)
144
- }
145
- }
146
-
147
- DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
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
- }
161
- source.replace(range[0], range[1] - 1, JSON.stringify(resultPath))
162
- } else {
163
- const replaceRange = `mpx_replace_path_${key}`
164
- source.replace(range[0], range[1] - 1, JSON.stringify(replaceRange))
165
- }
166
- }
167
- }
168
-
169
- makeSerializable(DynamicEntryDependency, '@mpxjs/webpack-plugin/lib/dependencies/DynamicEntryDependency')
170
-
171
- module.exports = DynamicEntryDependency
@@ -1,24 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const makeSerializable = require('webpack/lib/util/makeSerializable')
3
-
4
- class FlagPluginDependency extends NullDependency {
5
- get type () {
6
- return 'mpx flag plugin'
7
- }
8
-
9
- mpxAction (module, compilation, callback) {
10
- const mpx = compilation.__mpx__
11
- mpx.isPluginMode = true
12
- mpx.getEntryNode(module, 'plugin')
13
- return callback()
14
- }
15
- }
16
-
17
- FlagPluginDependency.Template = class FlagPluginDependencyTemplate {
18
- apply () {
19
- }
20
- }
21
-
22
- makeSerializable(FlagPluginDependency, '@mpxjs/webpack-plugin/lib/dependencies/FlagPluginDependency')
23
-
24
- module.exports = FlagPluginDependency
@@ -1,43 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const makeSerializable = require('webpack/lib/util/makeSerializable')
3
-
4
- class InjectDependency extends NullDependency {
5
- constructor (options = {}) {
6
- super()
7
- this.content = options.content
8
- this.index = options.index || 0
9
- }
10
-
11
- get type () {
12
- return 'mpx inject'
13
- }
14
-
15
- updateHash (hash, context) {
16
- hash.update(this.content)
17
- super.updateHash(hash, context)
18
- }
19
-
20
- serialize (context) {
21
- const { write } = context
22
- write(this.content)
23
- write(this.index)
24
- super.serialize(context)
25
- }
26
-
27
- deserialize (context) {
28
- const { read } = context
29
- this.content = read()
30
- this.index = read()
31
- super.deserialize(context)
32
- }
33
- }
34
-
35
- InjectDependency.Template = class InjectDependencyTemplate {
36
- apply (dep, source) {
37
- source.insert(dep.index, '/* mpx inject */ ' + dep.content)
38
- }
39
- }
40
-
41
- makeSerializable(InjectDependency, '@mpxjs/webpack-plugin/lib/dependencies/InjectDependency')
42
-
43
- module.exports = InjectDependency
@@ -1,50 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const makeSerializable = require('webpack/lib/util/makeSerializable')
3
- const addQuery = require('../utils/add-query')
4
-
5
- class RecordGlobalComponentsDependency extends NullDependency {
6
- constructor (usingComponents, context) {
7
- super()
8
- this.usingComponents = usingComponents
9
- this.context = context
10
- }
11
-
12
- get type () {
13
- return 'mpx record global components'
14
- }
15
-
16
- mpxAction (module, compilation, callback) {
17
- const mpx = compilation.__mpx__
18
- const { usingComponents, context } = this
19
- Object.keys(usingComponents).forEach((key) => {
20
- const request = usingComponents[key]
21
- mpx.usingComponents[key] = addQuery(request, {
22
- context
23
- })
24
- })
25
- return callback()
26
- }
27
-
28
- serialize (context) {
29
- const { write } = context
30
- write(this.usingComponents)
31
- write(this.context)
32
- super.serialize(context)
33
- }
34
-
35
- deserialize (context) {
36
- const { read } = context
37
- this.usingComponents = read()
38
- this.context = read()
39
- super.deserialize(context)
40
- }
41
- }
42
-
43
- RecordGlobalComponentsDependency.Template = class RecordGlobalComponentsDependencyTemplate {
44
- apply () {
45
- }
46
- }
47
-
48
- makeSerializable(RecordGlobalComponentsDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordGlobalComponentsDependency')
49
-
50
- module.exports = RecordGlobalComponentsDependency
@@ -1,44 +0,0 @@
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
@@ -1,62 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,88 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const parseRequest = require('../utils/parse-request')
3
- const makeSerializable = require('webpack/lib/util/makeSerializable')
4
-
5
- class ResolveDependency extends NullDependency {
6
- constructor (resource, packageName, issuerResource, range) {
7
- super()
8
- this.resource = resource
9
- this.packageName = packageName
10
- this.issuerResource = issuerResource
11
- this.range = range
12
- this.compilation = null
13
- }
14
-
15
- get type () {
16
- return 'mpx resolve'
17
- }
18
-
19
- mpxAction (module, compilation, callback) {
20
- this.compilation = compilation
21
- return callback()
22
- }
23
-
24
- getResolved () {
25
- const { resource, packageName, compilation } = this
26
- if (!compilation) return ''
27
- const mpx = compilation.__mpx__
28
- if (!mpx) return ''
29
- const { pagesMap, componentsMap, staticResourcesMap } = mpx
30
- const { resourcePath } = parseRequest(resource)
31
- const currentComponentsMap = componentsMap[packageName]
32
- const mainComponentsMap = componentsMap.main
33
- const currentStaticResourcesMap = staticResourcesMap[packageName]
34
- const mainStaticResourcesMap = staticResourcesMap.main
35
- return pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
36
- }
37
-
38
- // resolved可能会动态变更,需用此更新hash
39
- updateHash (hash, context) {
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
- }
47
- super.updateHash(hash, context)
48
- }
49
-
50
- serialize (context) {
51
- const { write } = context
52
- write(this.resource)
53
- write(this.packageName)
54
- write(this.issuerResource)
55
- write(this.range)
56
- super.serialize(context)
57
- }
58
-
59
- deserialize (context) {
60
- const { read } = context
61
- this.resource = read()
62
- this.packageName = read()
63
- this.issuerResource = read()
64
- this.range = read()
65
- super.deserialize(context)
66
- }
67
- }
68
-
69
- ResolveDependency.Template = class ResolveDependencyTemplate {
70
- apply (dep, source) {
71
- const content = this.getContent(dep)
72
- source.replace(dep.range[0], dep.range[1] - 1, content)
73
- }
74
-
75
- getContent (dep) {
76
- const { resolved = '', compilation } = dep
77
- const publicPath = compilation.outputOptions.publicPath || ''
78
- // for tenon
79
- if (dep.compilation.__mpx__.mode === 'tenon') {
80
- return `getRelativePath(currentURL, ${JSON.stringify(resolved)}) + '.js'`
81
- }
82
- return JSON.stringify(publicPath + resolved)
83
- }
84
- }
85
-
86
- makeSerializable(ResolveDependency, '@mpxjs/webpack-plugin/lib/dependencies/ResolveDependency')
87
-
88
- module.exports = ResolveDependency
@@ -1,52 +0,0 @@
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
- }