@mpxjs/webpack-plugin 2.9.39 → 2.9.41-react.0

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 (63) hide show
  1. package/lib/config.js +63 -97
  2. package/lib/dependencies/{RecordVueContentDependency.js → RecordLoaderContentDependency.js} +5 -5
  3. package/lib/dependencies/ResolveDependency.js +2 -2
  4. package/lib/helpers.js +5 -1
  5. package/lib/index.js +26 -21
  6. package/lib/loader.js +43 -97
  7. package/lib/native-loader.js +0 -1
  8. package/lib/platform/index.js +3 -0
  9. package/lib/platform/style/wx/index.js +414 -0
  10. package/lib/platform/template/wx/component-config/button.js +36 -0
  11. package/lib/platform/template/wx/component-config/image.js +15 -0
  12. package/lib/platform/template/wx/component-config/input.js +41 -0
  13. package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
  14. package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
  15. package/lib/platform/template/wx/component-config/swiper.js +25 -1
  16. package/lib/platform/template/wx/component-config/text.js +15 -0
  17. package/lib/platform/template/wx/component-config/textarea.js +39 -0
  18. package/lib/platform/template/wx/component-config/unsupported.js +18 -0
  19. package/lib/platform/template/wx/component-config/view.js +14 -0
  20. package/lib/platform/template/wx/index.js +88 -4
  21. package/lib/react/index.js +104 -0
  22. package/lib/react/processJSON.js +361 -0
  23. package/lib/react/processMainScript.js +21 -0
  24. package/lib/react/processScript.js +70 -0
  25. package/lib/react/processStyles.js +69 -0
  26. package/lib/react/processTemplate.js +153 -0
  27. package/lib/react/script-helper.js +133 -0
  28. package/lib/react/style-helper.js +91 -0
  29. package/lib/resolver/PackageEntryPlugin.js +1 -0
  30. package/lib/runtime/components/react/event.config.ts +32 -0
  31. package/lib/runtime/components/react/getInnerListeners.ts +289 -0
  32. package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
  33. package/lib/runtime/components/react/mpx-button.tsx +402 -0
  34. package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
  35. package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
  36. package/lib/runtime/components/react/mpx-input.tsx +389 -0
  37. package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
  38. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +398 -0
  39. package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
  40. package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
  41. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
  42. package/lib/runtime/components/react/mpx-text.tsx +106 -0
  43. package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
  44. package/lib/runtime/components/react/mpx-view.tsx +397 -0
  45. package/lib/runtime/components/react/useNodesRef.ts +39 -0
  46. package/lib/runtime/components/react/utils.ts +92 -0
  47. package/lib/runtime/optionProcessorReact.d.ts +9 -0
  48. package/lib/runtime/optionProcessorReact.js +21 -0
  49. package/lib/runtime/stringify.wxs +3 -8
  50. package/lib/style-compiler/index.js +2 -1
  51. package/lib/template-compiler/compiler.js +293 -38
  52. package/lib/template-compiler/gen-node-react.js +95 -0
  53. package/lib/template-compiler/index.js +15 -24
  54. package/lib/utils/env.js +17 -0
  55. package/lib/utils/make-map.js +1 -1
  56. package/lib/utils/shallow-stringify.js +12 -12
  57. package/lib/web/index.js +123 -0
  58. package/lib/web/processJSON.js +3 -3
  59. package/lib/web/processMainScript.js +25 -23
  60. package/lib/web/processScript.js +12 -16
  61. package/lib/web/processTemplate.js +13 -12
  62. package/lib/web/script-helper.js +14 -22
  63. 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
  }
@@ -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,7 @@ 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.partialCompileRules = options.partialCompileRules || null
179
184
  options.asyncSubpackageRules = options.asyncSubpackageRules || []
180
185
  options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
181
186
  options.retryRequireAsync = options.retryRequireAsync || false
@@ -299,7 +304,7 @@ class MpxWebpackPlugin {
299
304
  // 将entry export标记为used且不可mangle,避免require.async生成的js chunk在生产环境下报错
300
305
  new FlagEntryExportAsUsedPlugin(true, 'entry').apply(compiler)
301
306
 
302
- if (this.options.mode !== 'web') {
307
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
303
308
  // 强制设置publicPath为'/'
304
309
  if (compiler.options.output.publicPath && compiler.options.output.publicPath !== publicPath) {
305
310
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.publicPath to be ${publicPath} only, custom options.output.publicPath will be ignored!`)
@@ -327,7 +332,6 @@ class MpxWebpackPlugin {
327
332
  const addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
328
333
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
329
334
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
330
-
331
335
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
332
336
 
333
337
  if (Array.isArray(compiler.options.resolve.plugins)) {
@@ -343,7 +347,7 @@ class MpxWebpackPlugin {
343
347
  compiler.options.resolve.plugins.push(dynamicPlugin)
344
348
 
345
349
  const optimization = compiler.options.optimization
346
- if (this.options.mode !== 'web') {
350
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
347
351
  optimization.runtimeChunk = {
348
352
  name: (entrypoint) => {
349
353
  for (const packageName in mpx.independentSubpackagesMap) {
@@ -359,7 +363,7 @@ class MpxWebpackPlugin {
359
363
  let splitChunksOptions = null
360
364
  let splitChunksPlugin = null
361
365
  // 输出web ssr需要将optimization.splitChunks设置为false以关闭splitChunks
362
- if (optimization.splitChunks !== false) {
366
+ if (optimization.splitChunks !== false && !isReact(this.options.mode)) {
363
367
  splitChunksOptions = Object.assign({
364
368
  chunks: 'all',
365
369
  usedExports: optimization.usedExports === true,
@@ -417,7 +421,7 @@ class MpxWebpackPlugin {
417
421
 
418
422
  let mpx
419
423
 
420
- if (this.options.partialCompile) {
424
+ if (this.options.partialCompileRules) {
421
425
  function isResolvingPage (obj) {
422
426
  // valid query should start with '?'
423
427
  const query = parseQuery(obj.query || '?')
@@ -435,7 +439,7 @@ class MpxWebpackPlugin {
435
439
  if (obj.path.startsWith(require.resolve('./runtime/components/wx/default-page.mpx'))) {
436
440
  return callback(null, obj)
437
441
  }
438
- if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompile)) {
442
+ if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompileRules)) {
439
443
  const infix = obj.query ? '&' : '?'
440
444
  obj.query += `${infix}resourcePath=${obj.path}`
441
445
  obj.path = require.resolve('./runtime/components/wx/default-page.mpx')
@@ -593,8 +597,8 @@ class MpxWebpackPlugin {
593
597
  compilation.dependencyFactories.set(CommonJsExtractDependency, normalModuleFactory)
594
598
  compilation.dependencyTemplates.set(CommonJsExtractDependency, new CommonJsExtractDependency.Template())
595
599
 
596
- compilation.dependencyFactories.set(RecordVueContentDependency, new NullFactory())
597
- compilation.dependencyTemplates.set(RecordVueContentDependency, new RecordVueContentDependency.Template())
600
+ compilation.dependencyFactories.set(RecordLoaderContentDependency, new NullFactory())
601
+ compilation.dependencyTemplates.set(RecordLoaderContentDependency, new RecordLoaderContentDependency.Template())
598
602
 
599
603
  compilation.dependencyFactories.set(RecordRuntimeInfoDependency, new NullFactory())
600
604
  compilation.dependencyTemplates.set(RecordRuntimeInfoDependency, new RecordRuntimeInfoDependency.Template())
@@ -655,6 +659,7 @@ class MpxWebpackPlugin {
655
659
  env: this.options.env,
656
660
  externalClasses: this.options.externalClasses,
657
661
  projectRoot: this.options.projectRoot,
662
+ projectName: this.options.projectName,
658
663
  autoScopeRules: this.options.autoScopeRules,
659
664
  autoVirtualHostRules: this.options.autoVirtualHostRules,
660
665
  transRpxRules: this.options.transRpxRules,
@@ -664,7 +669,7 @@ class MpxWebpackPlugin {
664
669
  nativeConfig: this.options.nativeConfig,
665
670
  // 输出web专用配置
666
671
  webConfig: this.options.webConfig,
667
- vueContentCache: new Map(),
672
+ loaderContentCache: new Map(),
668
673
  tabBarMap: {},
669
674
  defs: processDefs(this.options.defs),
670
675
  i18n: this.options.i18n,
@@ -676,8 +681,8 @@ class MpxWebpackPlugin {
676
681
  useRelativePath: this.options.useRelativePath,
677
682
  removedChunks: [],
678
683
  forceProxyEventRules: this.options.forceProxyEventRules,
679
- supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'web' || this.options.mode === 'ali',
680
- partialCompile: this.options.partialCompile,
684
+ supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || isWeb(this.options.mode),
685
+ partialCompileRules: this.options.partialCompileRules,
681
686
  collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
682
687
  const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
683
688
  hasPage: false,
@@ -1123,7 +1128,7 @@ class MpxWebpackPlugin {
1123
1128
  // 自动使用分包配置修改splitChunksPlugin配置
1124
1129
  if (splitChunksPlugin) {
1125
1130
  let needInit = false
1126
- if (mpx.mode === 'web') {
1131
+ if (isWeb(mpx.mode)) {
1127
1132
  // web独立处理splitChunk
1128
1133
  if (!hasOwn(splitChunksOptions.cacheGroups, 'main')) {
1129
1134
  splitChunksOptions.cacheGroups.main = {
@@ -1157,7 +1162,7 @@ class MpxWebpackPlugin {
1157
1162
 
1158
1163
  JavascriptModulesPlugin.getCompilationHooks(compilation).renderModuleContent.tap('MpxWebpackPlugin', (source, module, renderContext) => {
1159
1164
  // 处理dll产生的external模块
1160
- if (module.external && module.userRequest.startsWith('dll-reference ') && mpx.mode !== 'web') {
1165
+ if (module.external && module.userRequest.startsWith('dll-reference ') && !isWeb(mpx.mode) && !isReact(mpx.mode)) {
1161
1166
  const chunk = renderContext.chunk
1162
1167
  const request = module.request
1163
1168
  let relativePath = toPosix(path.relative(path.dirname(chunk.name), request))
@@ -1309,7 +1314,7 @@ class MpxWebpackPlugin {
1309
1314
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1310
1315
  // wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1311
1316
  if (mpx.supportRequireAsync) {
1312
- if (mpx.mode === 'web') {
1317
+ if (isWeb(mpx.mode)) {
1313
1318
  const depBlock = new AsyncDependenciesBlock(
1314
1319
  {
1315
1320
  name: tarRoot
@@ -1514,8 +1519,8 @@ class MpxWebpackPlugin {
1514
1519
  parser.hooks.call.for('App').tap('MpxWebpackPlugin', (expr) => {
1515
1520
  transGlobalObject(expr.callee)
1516
1521
  })
1517
- if (mpx.mode === 'ali' || mpx.mode === 'web') {
1518
- // 支付宝和web不支持Behaviors
1522
+ if (mpx.mode === 'ali' || isWeb(mpx.mode) || isReact(mpx.mode)) {
1523
+ // 支付宝、web和react不支持Behaviors
1519
1524
  parser.hooks.call.for('Behavior').tap('MpxWebpackPlugin', (expr) => {
1520
1525
  transGlobalObject(expr.callee)
1521
1526
  })
@@ -1532,7 +1537,7 @@ class MpxWebpackPlugin {
1532
1537
  name: 'MpxWebpackPlugin',
1533
1538
  stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONS
1534
1539
  }, () => {
1535
- if (mpx.mode === 'web') return
1540
+ if (isWeb(mpx.mode) || isReact(mpx.mode)) return
1536
1541
 
1537
1542
  if (this.options.generateBuildMap) {
1538
1543
  const pagesMap = compilation.__mpx__.pagesMap
@@ -1771,7 +1776,7 @@ try {
1771
1776
  createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
1772
1777
  }
1773
1778
 
1774
- if (mpx.mode === 'web') {
1779
+ if (isWeb(mpx.mode)) {
1775
1780
  const mpxStyleOptions = queryObj.mpxStyleOptions
1776
1781
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1777
1782
  const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')