@mpxjs/webpack-plugin 2.9.40 → 2.9.41

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 (66) hide show
  1. package/lib/config.js +63 -97
  2. package/lib/dependencies/DynamicEntryDependency.js +13 -4
  3. package/lib/dependencies/{RecordVueContentDependency.js → RecordLoaderContentDependency.js} +5 -5
  4. package/lib/dependencies/ResolveDependency.js +2 -2
  5. package/lib/helpers.js +5 -1
  6. package/lib/index.js +59 -45
  7. package/lib/json-compiler/helper.js +6 -3
  8. package/lib/json-compiler/index.js +9 -7
  9. package/lib/loader.js +43 -97
  10. package/lib/native-loader.js +0 -1
  11. package/lib/platform/index.js +3 -0
  12. package/lib/platform/style/wx/index.js +414 -0
  13. package/lib/platform/template/wx/component-config/button.js +36 -0
  14. package/lib/platform/template/wx/component-config/image.js +15 -0
  15. package/lib/platform/template/wx/component-config/input.js +41 -0
  16. package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
  17. package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
  18. package/lib/platform/template/wx/component-config/swiper.js +25 -1
  19. package/lib/platform/template/wx/component-config/text.js +15 -0
  20. package/lib/platform/template/wx/component-config/textarea.js +39 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +18 -0
  22. package/lib/platform/template/wx/component-config/view.js +14 -0
  23. package/lib/platform/template/wx/index.js +88 -4
  24. package/lib/react/index.js +104 -0
  25. package/lib/react/processJSON.js +361 -0
  26. package/lib/react/processMainScript.js +21 -0
  27. package/lib/react/processScript.js +70 -0
  28. package/lib/react/processStyles.js +69 -0
  29. package/lib/react/processTemplate.js +152 -0
  30. package/lib/react/script-helper.js +133 -0
  31. package/lib/react/style-helper.js +91 -0
  32. package/lib/resolver/PackageEntryPlugin.js +1 -0
  33. package/lib/runtime/components/react/event.config.ts +32 -0
  34. package/lib/runtime/components/react/getInnerListeners.ts +289 -0
  35. package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
  36. package/lib/runtime/components/react/mpx-button.tsx +402 -0
  37. package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
  38. package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
  39. package/lib/runtime/components/react/mpx-input.tsx +389 -0
  40. package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
  41. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +398 -0
  42. package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
  43. package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
  44. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
  45. package/lib/runtime/components/react/mpx-text.tsx +106 -0
  46. package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
  47. package/lib/runtime/components/react/mpx-view.tsx +397 -0
  48. package/lib/runtime/components/react/useNodesRef.ts +39 -0
  49. package/lib/runtime/components/react/utils.ts +92 -0
  50. package/lib/runtime/optionProcessorReact.d.ts +9 -0
  51. package/lib/runtime/optionProcessorReact.js +21 -0
  52. package/lib/runtime/stringify.wxs +10 -28
  53. package/lib/style-compiler/index.js +2 -1
  54. package/lib/template-compiler/compiler.js +280 -37
  55. package/lib/template-compiler/gen-node-react.js +95 -0
  56. package/lib/template-compiler/index.js +15 -24
  57. package/lib/utils/env.js +17 -0
  58. package/lib/utils/make-map.js +1 -1
  59. package/lib/utils/shallow-stringify.js +12 -12
  60. package/lib/web/index.js +123 -0
  61. package/lib/web/processJSON.js +3 -3
  62. package/lib/web/processMainScript.js +25 -23
  63. package/lib/web/processScript.js +12 -16
  64. package/lib/web/processTemplate.js +13 -12
  65. package/lib/web/script-helper.js +14 -22
  66. package/package.json +4 -3
package/lib/config.js CHANGED
@@ -1,3 +1,51 @@
1
+ const reactConfig = {
2
+ event: {
3
+ parseEvent (attr) {
4
+ const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
5
+ if (match) {
6
+ return {
7
+ prefix: match[1],
8
+ eventName: match[2].replace(/^./, function (match) {
9
+ return match.toLowerCase()
10
+ }),
11
+ modifier: match[3]
12
+ }
13
+ }
14
+ },
15
+ getEvent (eventName, prefix = 'bind') {
16
+ return prefix + eventName
17
+ },
18
+ defaultModelProp: 'value',
19
+ defaultModelEvent: 'input',
20
+ defaultModelValuePath: 'value'
21
+ },
22
+ wxs: {
23
+ tag: 'wxs',
24
+ module: 'module',
25
+ src: 'src',
26
+ ext: '.wxs',
27
+ templatePrefix: 'module.exports = \n'
28
+ },
29
+ directive: {
30
+ if: 'wx:if',
31
+ elseif: 'wx:elif',
32
+ else: 'wx:else',
33
+ model: 'wx:model',
34
+ modelProp: 'wx:model-prop',
35
+ modelEvent: 'wx:model-event',
36
+ modelValuePath: 'wx:model-value-path',
37
+ modelFilter: 'wx:model-filter',
38
+ for: 'wx:for',
39
+ forIndex: 'wx:for-index',
40
+ forItem: 'wx:for-item',
41
+ key: 'wx:key',
42
+ dynamicClass: 'wx:class',
43
+ dynamicStyle: 'wx:style',
44
+ ref: 'wx:ref',
45
+ show: 'wx:show'
46
+ }
47
+ }
48
+
1
49
  module.exports = {
2
50
  wx: {
3
51
  typeExtMap: {
@@ -28,18 +76,7 @@ module.exports = {
28
76
  },
29
77
  defaultModelProp: 'value',
30
78
  defaultModelEvent: 'input',
31
- defaultModelValuePath: 'value',
32
- shallowStringify (obj) {
33
- const arr = []
34
- for (const key in obj) {
35
- let value = obj[key]
36
- if (Array.isArray(value)) {
37
- value = `[${value.join(',')}]`
38
- }
39
- arr.push(`${key}:${value}`)
40
- }
41
- return ` {${arr.join(',')}} `
42
- }
79
+ defaultModelValuePath: 'value'
43
80
  },
44
81
  wxs: {
45
82
  tag: 'wxs',
@@ -103,18 +140,7 @@ module.exports = {
103
140
  },
104
141
  defaultModelProp: 'value',
105
142
  defaultModelEvent: 'input',
106
- defaultModelValuePath: 'value',
107
- shallowStringify (obj) {
108
- const arr = []
109
- for (const key in obj) {
110
- let value = obj[key]
111
- if (Array.isArray(value)) {
112
- value = `[${value.join(',')}]`
113
- }
114
- arr.push(`${key}:${value}`)
115
- }
116
- return ` {${arr.join(',')}} `
117
- }
143
+ defaultModelValuePath: 'value'
118
144
  },
119
145
  wxs: {
120
146
  tag: 'import-sjs',
@@ -151,6 +177,7 @@ module.exports = {
151
177
  styles: '.css'
152
178
  },
153
179
  tabBar: {
180
+ customKey: 'custom',
154
181
  itemKey: 'list',
155
182
  iconKey: 'iconPath',
156
183
  activeIconKey: 'selectedIconPath'
@@ -171,18 +198,7 @@ module.exports = {
171
198
  },
172
199
  defaultModelProp: 'value',
173
200
  defaultModelEvent: 'input',
174
- defaultModelValuePath: 'value',
175
- shallowStringify (obj) {
176
- const arr = []
177
- for (const key in obj) {
178
- let value = obj[key]
179
- if (Array.isArray(value)) {
180
- value = `[${value.join(',')}]`
181
- }
182
- arr.push(`${key}:${value}`)
183
- }
184
- return ` {${arr.join(',')}} `
185
- }
201
+ defaultModelValuePath: 'value'
186
202
  },
187
203
  wxs: {
188
204
  tag: 'import-sjs',
@@ -239,18 +255,7 @@ module.exports = {
239
255
  },
240
256
  defaultModelProp: 'value',
241
257
  defaultModelEvent: 'input',
242
- defaultModelValuePath: 'value',
243
- shallowStringify (obj) {
244
- const arr = []
245
- for (const key in obj) {
246
- let value = obj[key]
247
- if (Array.isArray(value)) {
248
- value = `[${value.join(',')}]`
249
- }
250
- arr.push(`${key}:${value}`)
251
- }
252
- return `({${arr.join(',')}})`
253
- }
258
+ defaultModelValuePath: 'value'
254
259
  },
255
260
  wxs: {
256
261
  tag: 'qs',
@@ -286,6 +291,7 @@ module.exports = {
286
291
  styles: '.ttss'
287
292
  },
288
293
  tabBar: {
294
+ customKey: 'custom',
289
295
  itemKey: 'list',
290
296
  iconKey: 'iconPath',
291
297
  activeIconKey: 'selectedIconPath'
@@ -306,18 +312,7 @@ module.exports = {
306
312
  },
307
313
  defaultModelProp: 'value',
308
314
  defaultModelEvent: 'input',
309
- defaultModelValuePath: 'value',
310
- shallowStringify (obj) {
311
- const arr = []
312
- for (const key in obj) {
313
- let value = obj[key]
314
- if (Array.isArray(value)) {
315
- value = `[${value.join(',')}]`
316
- }
317
- arr.push(`${key}:${value}`)
318
- }
319
- return ` {${arr.join(',')}} `
320
- }
315
+ defaultModelValuePath: 'value'
321
316
  },
322
317
  wxs: {
323
318
  tag: 'sjs',
@@ -388,18 +383,7 @@ module.exports = {
388
383
  },
389
384
  defaultModelProp: 'value',
390
385
  defaultModelEvent: 'input',
391
- defaultModelValuePath: 'value',
392
- shallowStringify (obj) {
393
- const arr = []
394
- for (const key in obj) {
395
- let value = obj[key]
396
- if (Array.isArray(value)) {
397
- value = `[${value.join(',')}]`
398
- }
399
- arr.push(`${key}:${value}`)
400
- }
401
- return ` {${arr.join(',')}} `
402
- }
386
+ defaultModelValuePath: 'value'
403
387
  },
404
388
  wxs: {
405
389
  tag: 'qjs',
@@ -435,6 +419,7 @@ module.exports = {
435
419
  styles: '.jxss'
436
420
  },
437
421
  tabBar: {
422
+ customKey: 'custom',
438
423
  itemKey: 'list',
439
424
  iconKey: 'iconPath',
440
425
  activeIconKey: 'selectedIconPath'
@@ -455,18 +440,7 @@ module.exports = {
455
440
  },
456
441
  defaultModelProp: 'value',
457
442
  defaultModelEvent: 'input',
458
- defaultModelValuePath: 'value',
459
- shallowStringify (obj) {
460
- const arr = []
461
- for (const key in obj) {
462
- let value = obj[key]
463
- if (Array.isArray(value)) {
464
- value = `[${value.join(',')}]`
465
- }
466
- arr.push(`${key}:${value}`)
467
- }
468
- return ` {${arr.join(',')}} `
469
- }
443
+ defaultModelValuePath: 'value'
470
444
  },
471
445
  wxs: {
472
446
  tag: 'jds',
@@ -502,6 +476,7 @@ module.exports = {
502
476
  styles: '.ddss'
503
477
  },
504
478
  tabBar: {
479
+ customKey: 'custom',
505
480
  itemKey: 'list',
506
481
  iconKey: 'iconPath',
507
482
  activeIconKey: 'selectedIconPath'
@@ -522,18 +497,7 @@ module.exports = {
522
497
  },
523
498
  defaultModelProp: 'value',
524
499
  defaultModelEvent: 'input',
525
- defaultModelValuePath: 'value',
526
- shallowStringify (obj) {
527
- const arr = []
528
- for (const key in obj) {
529
- let value = obj[key]
530
- if (Array.isArray(value)) {
531
- value = `[${value.join(',')}]`
532
- }
533
- arr.push(`${key}:${value}`)
534
- }
535
- return ` {${arr.join(',')}} `
536
- }
500
+ defaultModelValuePath: 'value'
537
501
  },
538
502
  wxs: {
539
503
  tag: 'dds',
@@ -560,5 +524,7 @@ module.exports = {
560
524
  ref: 'dd:ref',
561
525
  show: 'dd:show'
562
526
  }
563
- }
527
+ },
528
+ ios: reactConfig,
529
+ android: reactConfig
564
530
  }
@@ -35,7 +35,7 @@ class DynamicEntryDependency extends NullDependency {
35
35
 
36
36
  addEntry (compilation, callback) {
37
37
  const mpx = compilation.__mpx__
38
- let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver } = this
38
+ let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver, extraOptions } = this
39
39
 
40
40
  async.waterfall([
41
41
  (callback) => {
@@ -89,6 +89,14 @@ class DynamicEntryDependency extends NullDependency {
89
89
  originEntryNode.addChild(mpx.getEntryNode(entryModule, entryType))
90
90
  })
91
91
  }
92
+ if (mpx.dynamicEntryInfo[packageName] && extraOptions.isAsync) {
93
+ mpx.dynamicEntryInfo[packageName].entries.forEach(entry => {
94
+ if (entry.resource === resource && entry.filename === filename && entry.entryType === entryType) {
95
+ entry.hasAsync = true
96
+ }
97
+ return entry
98
+ })
99
+ }
92
100
  // alreadyOutputted时直接返回,避免存在模块循环引用时死循环
93
101
  return callback(null, { resultPath })
94
102
  } else {
@@ -113,7 +121,8 @@ class DynamicEntryDependency extends NullDependency {
113
121
  resource,
114
122
  packageName,
115
123
  filename,
116
- entryType
124
+ entryType,
125
+ hasAsync: extraOptions.isAsync || false
117
126
  })
118
127
  }
119
128
  }
@@ -145,9 +154,9 @@ class DynamicEntryDependency extends NullDependency {
145
154
  mpx.subpackagesEntriesMap[packageRoot].push(this)
146
155
  callback()
147
156
  } else {
148
- this.addEntry(compilation, (err, { resultPath }) => {
157
+ this.addEntry(compilation, (err, result) => {
149
158
  if (err) return callback(err)
150
- this.resultPath = resultPath
159
+ this.resultPath = result.resultPath
151
160
  callback()
152
161
  })
153
162
  }
@@ -1,7 +1,7 @@
1
1
  const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
2
  const makeSerializable = require('webpack/lib/util/makeSerializable')
3
3
 
4
- class RecordVueContentDependency extends NullDependency {
4
+ class RecordLoaderContentDependency extends NullDependency {
5
5
  constructor (resourcePath, content) {
6
6
  super()
7
7
  this.resourcePath = resourcePath
@@ -14,7 +14,7 @@ class RecordVueContentDependency extends NullDependency {
14
14
 
15
15
  mpxAction (module, compilation, callback) {
16
16
  const mpx = compilation.__mpx__
17
- mpx.vueContentCache.set(this.resourcePath, this.content)
17
+ mpx.loaderContentCache.set(this.resourcePath, this.content)
18
18
  return callback()
19
19
  }
20
20
 
@@ -33,11 +33,11 @@ class RecordVueContentDependency extends NullDependency {
33
33
  }
34
34
  }
35
35
 
36
- RecordVueContentDependency.Template = class RecordVueContentDependencyTemplate {
36
+ RecordLoaderContentDependency.Template = class RecordLoaderContentDependencyTemplate {
37
37
  apply () {
38
38
  }
39
39
  }
40
40
 
41
- makeSerializable(RecordVueContentDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordVueContentDependency')
41
+ makeSerializable(RecordLoaderContentDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordLoaderContentDependency')
42
42
 
43
- module.exports = RecordVueContentDependency
43
+ module.exports = RecordLoaderContentDependency
@@ -27,7 +27,7 @@ class ResolveDependency extends NullDependency {
27
27
  if (!compilation) return ''
28
28
  const mpx = compilation.__mpx__
29
29
  if (!mpx) return ''
30
- const { pagesMap, componentsMap, staticResourcesMap, partialCompile } = mpx
30
+ const { pagesMap, componentsMap, staticResourcesMap, partialCompileRules } = mpx
31
31
  const { resourcePath } = parseRequest(resource)
32
32
  const currentComponentsMap = componentsMap[packageName]
33
33
  const mainComponentsMap = componentsMap.main
@@ -35,7 +35,7 @@ class ResolveDependency extends NullDependency {
35
35
  const mainStaticResourcesMap = staticResourcesMap.main
36
36
  const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
37
37
  if (!resolveResult) {
38
- if (!partialCompile || matchCondition(resourcePath, partialCompile)) {
38
+ if (!partialCompileRules || matchCondition(resourcePath, partialCompileRules)) {
39
39
  compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
40
40
  }
41
41
  }
package/lib/helpers.js CHANGED
@@ -19,7 +19,7 @@ module.exports = function createHelpers (loaderContext) {
19
19
 
20
20
  const { mode, env } = loaderContext.getMpx() || {}
21
21
 
22
- function getRequire (type, part, extraOptions, index) {
22
+ function getRequire (type, part, extraOptions = {}, index = 0) {
23
23
  let extract = false
24
24
  switch (type) {
25
25
  // eslint-disable-next-line no-fallthrough
@@ -28,6 +28,8 @@ module.exports = function createHelpers (loaderContext) {
28
28
  case 'template':
29
29
  extract = true
30
30
  }
31
+ // 允许外部强制关闭extract
32
+ if (extraOptions.extract === false) extract = false
31
33
  return (extract ? 'require.extract(' : 'require(') + getRequestString(type, part, extraOptions, index) + ')'
32
34
  }
33
35
 
@@ -70,6 +72,8 @@ module.exports = function createHelpers (loaderContext) {
70
72
  case 'template':
71
73
  options.extract = true
72
74
  }
75
+ // 允许外部强制关闭extract
76
+ if (extraOptions.extract === false) delete options.extract
73
77
 
74
78
  if (part.mode) options.mode = part.mode
75
79
 
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ const RecordIndependentDependency = require('./dependencies/RecordIndependentDep
39
39
  const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
40
40
  const FlagPluginDependency = require('./dependencies/FlagPluginDependency')
41
41
  const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
42
- const RecordVueContentDependency = require('./dependencies/RecordVueContentDependency')
42
+ const RecordLoaderContentDependency = require('./dependencies/RecordLoaderContentDependency')
43
43
  const RecordRuntimeInfoDependency = require('./dependencies/RecordRuntimeInfoDependency')
44
44
  const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
45
45
  const fixRelative = require('./utils/fix-relative')
@@ -65,6 +65,7 @@ const emitFile = require('./utils/emit-file')
65
65
  const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
66
66
  const isEmptyObject = require('./utils/is-empty-object')
67
67
  const DynamicPlugin = require('./resolver/DynamicPlugin')
68
+ const { isReact, isWeb } = require('./utils/env')
68
69
  require('./utils/check-core-version-match')
69
70
 
70
71
  const isProductionLikeMode = options => {
@@ -122,9 +123,12 @@ class MpxWebpackPlugin {
122
123
  if (options.mode !== options.srcMode && options.srcMode !== 'wx') {
123
124
  errors.push('MpxWebpackPlugin supports srcMode to be "wx" only temporarily!')
124
125
  }
125
- if (options.mode === 'web' && options.srcMode !== 'wx') {
126
+ if (isWeb(options.mode) && options.srcMode !== 'wx') {
126
127
  errors.push('MpxWebpackPlugin supports mode to be "web" only when srcMode is set to "wx"!')
127
128
  }
129
+ if (isReact(options.mode) && options.srcMode !== 'wx') {
130
+ errors.push('MpxWebpackPlugin supports mode to be "ios" or "android" only when srcMode is set to "wx"!')
131
+ }
128
132
  if (options.dynamicComponentRules && !options.dynamicRuntime) {
129
133
  errors.push('Please make sure you have set dynamicRuntime true in mpx webpack plugin config because you have use the dynamic runtime feature.')
130
134
  }
@@ -152,6 +156,7 @@ class MpxWebpackPlugin {
152
156
  return externalsMap[external] || external
153
157
  })
154
158
  options.projectRoot = options.projectRoot || process.cwd()
159
+ options.projectName = options.projectName || 'AwesomeProject'
155
160
  options.forceUsePageCtor = options.forceUsePageCtor || false
156
161
  options.postcssInlineConfig = options.postcssInlineConfig || {}
157
162
  options.transRpxRules = options.transRpxRules || null
@@ -175,7 +180,8 @@ class MpxWebpackPlugin {
175
180
  cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
176
181
  }, options.nativeConfig)
177
182
  options.webConfig = options.webConfig || {}
178
- options.partialCompile = options.mode !== 'web' && options.partialCompile
183
+ options.rnConfig = options.rnConfig || {}
184
+ options.partialCompileRules = options.partialCompileRules || null
179
185
  options.asyncSubpackageRules = options.asyncSubpackageRules || []
180
186
  options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
181
187
  options.retryRequireAsync = options.retryRequireAsync || false
@@ -299,7 +305,7 @@ class MpxWebpackPlugin {
299
305
  // 将entry export标记为used且不可mangle,避免require.async生成的js chunk在生产环境下报错
300
306
  new FlagEntryExportAsUsedPlugin(true, 'entry').apply(compiler)
301
307
 
302
- if (this.options.mode !== 'web') {
308
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
303
309
  // 强制设置publicPath为'/'
304
310
  if (compiler.options.output.publicPath && compiler.options.output.publicPath !== publicPath) {
305
311
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.publicPath to be ${publicPath} only, custom options.output.publicPath will be ignored!`)
@@ -327,7 +333,6 @@ class MpxWebpackPlugin {
327
333
  const addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
328
334
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
329
335
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
330
-
331
336
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
332
337
 
333
338
  if (Array.isArray(compiler.options.resolve.plugins)) {
@@ -343,7 +348,7 @@ class MpxWebpackPlugin {
343
348
  compiler.options.resolve.plugins.push(dynamicPlugin)
344
349
 
345
350
  const optimization = compiler.options.optimization
346
- if (this.options.mode !== 'web') {
351
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
347
352
  optimization.runtimeChunk = {
348
353
  name: (entrypoint) => {
349
354
  for (const packageName in mpx.independentSubpackagesMap) {
@@ -359,7 +364,7 @@ class MpxWebpackPlugin {
359
364
  let splitChunksOptions = null
360
365
  let splitChunksPlugin = null
361
366
  // 输出web ssr需要将optimization.splitChunks设置为false以关闭splitChunks
362
- if (optimization.splitChunks !== false) {
367
+ if (optimization.splitChunks !== false && !isReact(this.options.mode)) {
363
368
  splitChunksOptions = Object.assign({
364
369
  chunks: 'all',
365
370
  usedExports: optimization.usedExports === true,
@@ -417,7 +422,7 @@ class MpxWebpackPlugin {
417
422
 
418
423
  let mpx
419
424
 
420
- if (this.options.partialCompile) {
425
+ if (this.options.partialCompileRules) {
421
426
  function isResolvingPage (obj) {
422
427
  // valid query should start with '?'
423
428
  const query = parseQuery(obj.query || '?')
@@ -435,7 +440,7 @@ class MpxWebpackPlugin {
435
440
  if (obj.path.startsWith(require.resolve('./runtime/components/wx/default-page.mpx'))) {
436
441
  return callback(null, obj)
437
442
  }
438
- if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
443
+ if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompileRules)) {
439
444
  const infix = obj.query ? '&' : '?'
440
445
  obj.query += `${infix}resourcePath=${obj.path}`
441
446
  obj.path = require.resolve('./runtime/components/wx/default-page.mpx')
@@ -593,8 +598,8 @@ class MpxWebpackPlugin {
593
598
  compilation.dependencyFactories.set(CommonJsExtractDependency, normalModuleFactory)
594
599
  compilation.dependencyTemplates.set(CommonJsExtractDependency, new CommonJsExtractDependency.Template())
595
600
 
596
- compilation.dependencyFactories.set(RecordVueContentDependency, new NullFactory())
597
- compilation.dependencyTemplates.set(RecordVueContentDependency, new RecordVueContentDependency.Template())
601
+ compilation.dependencyFactories.set(RecordLoaderContentDependency, new NullFactory())
602
+ compilation.dependencyTemplates.set(RecordLoaderContentDependency, new RecordLoaderContentDependency.Template())
598
603
 
599
604
  compilation.dependencyFactories.set(RecordRuntimeInfoDependency, new NullFactory())
600
605
  compilation.dependencyTemplates.set(RecordRuntimeInfoDependency, new RecordRuntimeInfoDependency.Template())
@@ -655,6 +660,7 @@ class MpxWebpackPlugin {
655
660
  env: this.options.env,
656
661
  externalClasses: this.options.externalClasses,
657
662
  projectRoot: this.options.projectRoot,
663
+ projectName: this.options.projectName,
658
664
  autoScopeRules: this.options.autoScopeRules,
659
665
  autoVirtualHostRules: this.options.autoVirtualHostRules,
660
666
  transRpxRules: this.options.transRpxRules,
@@ -664,7 +670,9 @@ class MpxWebpackPlugin {
664
670
  nativeConfig: this.options.nativeConfig,
665
671
  // 输出web专用配置
666
672
  webConfig: this.options.webConfig,
667
- vueContentCache: new Map(),
673
+ // 输出rn专用配置
674
+ rnConfig: this.options.rnConfig,
675
+ loaderContentCache: new Map(),
668
676
  tabBarMap: {},
669
677
  defs: processDefs(this.options.defs),
670
678
  i18n: this.options.i18n,
@@ -676,9 +684,9 @@ class MpxWebpackPlugin {
676
684
  useRelativePath: this.options.useRelativePath,
677
685
  removedChunks: [],
678
686
  forceProxyEventRules: this.options.forceProxyEventRules,
679
- supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'web' || this.options.mode === 'ali',
680
- partialCompile: this.options.partialCompile,
681
- collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
687
+ supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || isWeb(this.options.mode),
688
+ partialCompileRules: this.options.partialCompileRules,
689
+ collectDynamicEntryInfo: ({ resource, packageName, filename, entryType, hasAsync }) => {
682
690
  const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
683
691
  hasPage: false,
684
692
  entries: []
@@ -687,7 +695,8 @@ class MpxWebpackPlugin {
687
695
  curInfo.entries.push({
688
696
  entryType,
689
697
  resource,
690
- filename
698
+ filename,
699
+ hasAsync
691
700
  })
692
701
  },
693
702
  asyncSubpackageRules: this.options.asyncSubpackageRules,
@@ -1123,7 +1132,7 @@ class MpxWebpackPlugin {
1123
1132
  // 自动使用分包配置修改splitChunksPlugin配置
1124
1133
  if (splitChunksPlugin) {
1125
1134
  let needInit = false
1126
- if (mpx.mode === 'web') {
1135
+ if (isWeb(mpx.mode)) {
1127
1136
  // web独立处理splitChunk
1128
1137
  if (!hasOwn(splitChunksOptions.cacheGroups, 'main')) {
1129
1138
  splitChunksOptions.cacheGroups.main = {
@@ -1157,7 +1166,7 @@ class MpxWebpackPlugin {
1157
1166
 
1158
1167
  JavascriptModulesPlugin.getCompilationHooks(compilation).renderModuleContent.tap('MpxWebpackPlugin', (source, module, renderContext) => {
1159
1168
  // 处理dll产生的external模块
1160
- if (module.external && module.userRequest.startsWith('dll-reference ') && mpx.mode !== 'web') {
1169
+ if (module.external && module.userRequest.startsWith('dll-reference ') && !isWeb(mpx.mode) && !isReact(mpx.mode)) {
1161
1170
  const chunk = renderContext.chunk
1162
1171
  const request = module.request
1163
1172
  let relativePath = toPosix(path.relative(path.dirname(chunk.name), request))
@@ -1239,31 +1248,35 @@ class MpxWebpackPlugin {
1239
1248
  compilation.hooks.processAssets.tap({
1240
1249
  name: 'MpxWebpackPlugin'
1241
1250
  }, (assets) => {
1242
- const dynamicAssets = {}
1243
- for (const packageName in mpx.runtimeInfo) {
1244
- for (const resourcePath in mpx.runtimeInfo[packageName]) {
1245
- const { moduleId, template, style, json } = mpx.runtimeInfo[packageName][resourcePath]
1246
- const templateAst = mpx.changeHashNameForAstNode(template.templateAst, json)
1247
- dynamicAssets[moduleId] = {
1248
- template: JSON.parse(templateAst),
1249
- styles: style.reduce((preV, curV) => {
1250
- preV.push(...curV)
1251
- return preV
1252
- }, [])
1253
- }
1251
+ try {
1252
+ const dynamicAssets = {}
1253
+ for (const packageName in mpx.runtimeInfo) {
1254
+ for (const resourcePath in mpx.runtimeInfo[packageName]) {
1255
+ const { moduleId, template, style, json } = mpx.runtimeInfo[packageName][resourcePath]
1256
+ const templateAst = mpx.changeHashNameForAstNode(template.templateAst, json)
1257
+ dynamicAssets[moduleId] = {
1258
+ template: JSON.parse(templateAst),
1259
+ styles: style.reduce((preV, curV) => {
1260
+ preV.push(...curV)
1261
+ return preV
1262
+ }, [])
1263
+ }
1254
1264
 
1255
- // 注入 dynamic slot dependency
1256
- const outputPath = mpx.componentsMap[packageName][resourcePath]
1257
- if (outputPath) {
1258
- const jsonAsset = outputPath + '.json'
1259
- const jsonContent = compilation.assets[jsonAsset].source()
1260
- compilation.assets[jsonAsset] = new RawSource(mpx.injectDynamicSlotDependencies(jsonContent, resourcePath))
1265
+ // 注入 dynamic slot dependency
1266
+ const outputPath = mpx.componentsMap[packageName][resourcePath]
1267
+ if (outputPath) {
1268
+ const jsonAsset = outputPath + '.json'
1269
+ const jsonContent = compilation.assets[jsonAsset].source()
1270
+ compilation.assets[jsonAsset] = new RawSource(mpx.injectDynamicSlotDependencies(jsonContent, resourcePath))
1271
+ }
1261
1272
  }
1262
1273
  }
1263
- }
1264
- if (!isEmptyObject(dynamicAssets)) {
1265
- // 产出 jsonAst 静态产物
1266
- compilation.assets['dynamic.json'] = new RawSource(JSON.stringify(dynamicAssets))
1274
+ if (!isEmptyObject(dynamicAssets)) {
1275
+ // 产出 jsonAst 静态产物
1276
+ compilation.assets['dynamic.json'] = new RawSource(JSON.stringify(dynamicAssets))
1277
+ }
1278
+ } catch (error) {
1279
+ compilation.errors.push(error)
1267
1280
  }
1268
1281
  })
1269
1282
 
@@ -1309,7 +1322,7 @@ class MpxWebpackPlugin {
1309
1322
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1310
1323
  // wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1311
1324
  if (mpx.supportRequireAsync) {
1312
- if (mpx.mode === 'web') {
1325
+ if (isWeb(mpx.mode)) {
1313
1326
  const depBlock = new AsyncDependenciesBlock(
1314
1327
  {
1315
1328
  name: tarRoot
@@ -1323,6 +1336,7 @@ class MpxWebpackPlugin {
1323
1336
  parser.state.current.addBlock(depBlock)
1324
1337
  } else {
1325
1338
  const dep = new DynamicEntryDependency(range, request, 'export', '', tarRoot, '', context, {
1339
+ isAsync: true,
1326
1340
  isRequireAsync: true,
1327
1341
  retryRequireAsync: !!this.options.retryRequireAsync
1328
1342
  })
@@ -1514,8 +1528,8 @@ class MpxWebpackPlugin {
1514
1528
  parser.hooks.call.for('App').tap('MpxWebpackPlugin', (expr) => {
1515
1529
  transGlobalObject(expr.callee)
1516
1530
  })
1517
- if (mpx.mode === 'ali' || mpx.mode === 'web') {
1518
- // 支付宝和web不支持Behaviors
1531
+ if (mpx.mode === 'ali' || isWeb(mpx.mode) || isReact(mpx.mode)) {
1532
+ // 支付宝、web和react不支持Behaviors
1519
1533
  parser.hooks.call.for('Behavior').tap('MpxWebpackPlugin', (expr) => {
1520
1534
  transGlobalObject(expr.callee)
1521
1535
  })
@@ -1532,7 +1546,7 @@ class MpxWebpackPlugin {
1532
1546
  name: 'MpxWebpackPlugin',
1533
1547
  stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONS
1534
1548
  }, () => {
1535
- if (mpx.mode === 'web') return
1549
+ if (isWeb(mpx.mode) || isReact(mpx.mode)) return
1536
1550
 
1537
1551
  if (this.options.generateBuildMap) {
1538
1552
  const pagesMap = compilation.__mpx__.pagesMap
@@ -1771,7 +1785,7 @@ try {
1771
1785
  createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
1772
1786
  }
1773
1787
 
1774
- if (mpx.mode === 'web') {
1788
+ if (isWeb(mpx.mode)) {
1775
1789
  const mpxStyleOptions = queryObj.mpxStyleOptions
1776
1790
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1777
1791
  const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')