@mpxjs/webpack-plugin 2.9.41-react.0 → 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.
@@ -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
  }
package/lib/index.js CHANGED
@@ -180,6 +180,7 @@ class MpxWebpackPlugin {
180
180
  cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
181
181
  }, options.nativeConfig)
182
182
  options.webConfig = options.webConfig || {}
183
+ options.rnConfig = options.rnConfig || {}
183
184
  options.partialCompileRules = options.partialCompileRules || null
184
185
  options.asyncSubpackageRules = options.asyncSubpackageRules || []
185
186
  options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
@@ -669,6 +670,8 @@ class MpxWebpackPlugin {
669
670
  nativeConfig: this.options.nativeConfig,
670
671
  // 输出web专用配置
671
672
  webConfig: this.options.webConfig,
673
+ // 输出rn专用配置
674
+ rnConfig: this.options.rnConfig,
672
675
  loaderContentCache: new Map(),
673
676
  tabBarMap: {},
674
677
  defs: processDefs(this.options.defs),
@@ -683,7 +686,7 @@ class MpxWebpackPlugin {
683
686
  forceProxyEventRules: this.options.forceProxyEventRules,
684
687
  supportRequireAsync: this.options.mode === 'wx' || this.options.mode === 'ali' || isWeb(this.options.mode),
685
688
  partialCompileRules: this.options.partialCompileRules,
686
- collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
689
+ collectDynamicEntryInfo: ({ resource, packageName, filename, entryType, hasAsync }) => {
687
690
  const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
688
691
  hasPage: false,
689
692
  entries: []
@@ -692,7 +695,8 @@ class MpxWebpackPlugin {
692
695
  curInfo.entries.push({
693
696
  entryType,
694
697
  resource,
695
- filename
698
+ filename,
699
+ hasAsync
696
700
  })
697
701
  },
698
702
  asyncSubpackageRules: this.options.asyncSubpackageRules,
@@ -1244,31 +1248,35 @@ class MpxWebpackPlugin {
1244
1248
  compilation.hooks.processAssets.tap({
1245
1249
  name: 'MpxWebpackPlugin'
1246
1250
  }, (assets) => {
1247
- const dynamicAssets = {}
1248
- for (const packageName in mpx.runtimeInfo) {
1249
- for (const resourcePath in mpx.runtimeInfo[packageName]) {
1250
- const { moduleId, template, style, json } = mpx.runtimeInfo[packageName][resourcePath]
1251
- const templateAst = mpx.changeHashNameForAstNode(template.templateAst, json)
1252
- dynamicAssets[moduleId] = {
1253
- template: JSON.parse(templateAst),
1254
- styles: style.reduce((preV, curV) => {
1255
- preV.push(...curV)
1256
- return preV
1257
- }, [])
1258
- }
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
+ }
1259
1264
 
1260
- // 注入 dynamic slot dependency
1261
- const outputPath = mpx.componentsMap[packageName][resourcePath]
1262
- if (outputPath) {
1263
- const jsonAsset = outputPath + '.json'
1264
- const jsonContent = compilation.assets[jsonAsset].source()
1265
- 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
+ }
1266
1272
  }
1267
1273
  }
1268
- }
1269
- if (!isEmptyObject(dynamicAssets)) {
1270
- // 产出 jsonAst 静态产物
1271
- 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)
1272
1280
  }
1273
1281
  })
1274
1282
 
@@ -1328,6 +1336,7 @@ class MpxWebpackPlugin {
1328
1336
  parser.state.current.addBlock(depBlock)
1329
1337
  } else {
1330
1338
  const dep = new DynamicEntryDependency(range, request, 'export', '', tarRoot, '', context, {
1339
+ isAsync: true,
1331
1340
  isRequireAsync: true,
1332
1341
  retryRequireAsync: !!this.options.retryRequireAsync
1333
1342
  })
@@ -7,6 +7,7 @@ const addQuery = require('../utils/add-query')
7
7
  const loaderUtils = require('loader-utils')
8
8
  const resolve = require('../utils/resolve')
9
9
  const { matchCondition } = require('../utils/match-condition')
10
+ const { isWeb, isReact } = require('../utils/env')
10
11
 
11
12
  module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
12
13
  const mpx = loaderContext.getMpx()
@@ -58,11 +59,13 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
58
59
  // 目前只有微信支持分包异步化
59
60
  if (supportRequireAsync) {
60
61
  tarRoot = queryObj.root
62
+ extraOptions.isAsync = true
61
63
  }
62
64
  } else if (!queryObj.root && asyncSubpackageRules && supportRequireAsync) {
63
65
  for (const item of asyncSubpackageRules) {
64
66
  if (matchCondition(resourcePath, item)) {
65
67
  tarRoot = item.root
68
+ extraOptions.isAsync = true
66
69
  placeholder = item.placeholder
67
70
  break
68
71
  }
@@ -74,7 +77,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
74
77
  const resourceName = path.join(parsed.dir, parsed.name)
75
78
 
76
79
  if (!outputPath) {
77
- if (isScript(ext) && resourceName.includes('node_modules') && mode !== 'web') {
80
+ if (isScript(ext) && resourceName.includes('node_modules') && !isWeb(mode) && !isReact(mode)) {
78
81
  let root = info.descriptionFileRoot
79
82
  let name = 'nativeComponent'
80
83
  if (info.descriptionFileData) {
@@ -92,7 +95,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
92
95
  outputPath = getOutputPath(resourcePath, 'component')
93
96
  }
94
97
  }
95
- if (isScript(ext) && mode !== 'web') {
98
+ if (isScript(ext) && !isWeb(mode) && !isReact(mode)) {
96
99
  resource = `!!${nativeLoaderPath}!${resource}`
97
100
  }
98
101
 
@@ -137,7 +140,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
137
140
  outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
138
141
  }
139
142
  }
140
- if (isScript(ext) && mode !== 'web') {
143
+ if (isScript(ext) && !isWeb(mode) && !isReact(mode)) {
141
144
  resource = `!!${nativeLoaderPath}!${resource}`
142
145
  }
143
146
  const entry = getDynamicEntry(resource, 'page', outputPath, tarRoot, publicPath + tarRoot)
@@ -73,11 +73,11 @@ module.exports = function (content) {
73
73
  const normalizePlaceholder = (placeholder) => {
74
74
  if (typeof placeholder === 'string') {
75
75
  const placeholderMap = mode === 'ali'
76
- ? {
77
- view: { name: 'mpx-view', resource: mpxViewPath },
78
- text: { name: 'mpx-text', resource: mpxTextPath }
79
- }
80
- : {}
76
+ ? {
77
+ view: { name: 'mpx-view', resource: mpxViewPath },
78
+ text: { name: 'mpx-text', resource: mpxTextPath }
79
+ }
80
+ : {}
81
81
  placeholder = placeholderMap[placeholder] || { name: placeholder }
82
82
  }
83
83
  if (!placeholder.name) {
@@ -275,7 +275,8 @@ module.exports = function (content) {
275
275
  callback()
276
276
  }
277
277
  })
278
- }, () => {
278
+ }, (err) => {
279
+ if (err) return callback(err)
279
280
  const mpxCustomElementPath = resolveMpxCustomElementPath(packageName)
280
281
  if (runtimeCompile) {
281
282
  components.element = mpxCustomElementPath
@@ -325,7 +326,8 @@ module.exports = function (content) {
325
326
  }
326
327
  callback()
327
328
  })
328
- }, () => {
329
+ }, (err) => {
330
+ if (err) return callback(err)
329
331
  if (tarRoot && subPackagesCfg) {
330
332
  if (!subPackagesCfg[tarRoot].pages.length && pagesCache[0]) {
331
333
  subPackagesCfg[tarRoot].pages.push(pagesCache[0])
@@ -26,13 +26,13 @@ module.exports = function (script, {
26
26
  import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
27
27
  import { NavigationContainer, createNavigationContainerRef, StackActions } from '@react-navigation/native'
28
28
  import { createNativeStackNavigator } from '@react-navigation/native-stack'
29
- import { RootSiblingParent } from 'react-native-root-siblings'
29
+ import { Provider } from '@ant-design/react-native'
30
30
  global.__navigationHelper = {
31
31
  NavigationContainer: NavigationContainer,
32
32
  createNavigationContainerRef: createNavigationContainerRef,
33
33
  createNativeStackNavigator: createNativeStackNavigator,
34
34
  StackActions: StackActions,
35
- RootSiblingParent: RootSiblingParent
35
+ Provider: Provider
36
36
  }\n`
37
37
  const { pagesMap, firstPage } = buildPagesMap({
38
38
  localPagesMap,
@@ -59,7 +59,7 @@ global.__navigationHelper = {
59
59
  jsonConfig
60
60
  })
61
61
 
62
- output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, componentsMap })
62
+ output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap })
63
63
  output += getRequireScript({ ctorType, script, loaderContext })
64
64
  output += `export default global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
65
65
  }
@@ -112,14 +112,13 @@ module.exports = function (template, {
112
112
  try {
113
113
  const ignoreMap = Object.assign({
114
114
  createElement: true,
115
- components: true,
116
- getNativeComponent: true,
115
+ getComponent: true,
117
116
  rootProps: true
118
117
  }, meta.wxsModuleMap)
119
118
  const bindResult = bindThis.transform(rawCode, {
120
119
  ignoreMap
121
120
  })
122
- output += `global.currentInject.render = function (createElement, components, getNativeComponent, rootProps) {
121
+ output += `global.currentInject.render = function (createElement, getComponent, rootProps) {
123
122
  return ${bindResult.code}
124
123
  };\n`
125
124
  } catch (e) {
@@ -8,38 +8,25 @@ function objectKeys (obj) {
8
8
  '[': ']',
9
9
  '(': ')'
10
10
  }
11
- var shiftMap = {
12
- 'n': '\n',
13
- 'b': '\b',
14
- 'f': '\f',
15
- 'r': '\r',
16
- 't': '\t'
17
- }
18
11
  if (typeof obj === 'object') {
19
12
  var objStr = JSON.stringify(obj)
20
13
  if (objStr[0] === '{' && objStr[objStr.length - 1] === '}') {
21
- var key = ''
22
14
  var inKey = true
23
15
  var stack = []
24
- var shift = false
16
+ var keyStart = 0
17
+ var keyEnd = 0
25
18
  for (var i = 1; i < objStr.length - 1; i++) {
26
19
  var item = objStr[i]
27
20
  var lastItem = objStr[i - 1]
28
21
  if (inKey) {
29
- if (item === ':' && lastItem === '"') {
30
- keys.push(key.slice(1, -1))
31
- key = ''
22
+ if (item === ':' && keyEnd === i - 1) {
23
+ keys.push(objStr.slice(keyStart + 1, keyEnd))
32
24
  inKey = false
33
25
  } else {
34
- if (shift === false && item === '\\') {
35
- shift = true
36
- continue
37
- }
38
- if (shift) {
39
- item = shiftMap[item] || item
40
- shift = false
26
+ if (item === '"' && lastItem !== '\\') {
27
+ keyStart = keyEnd
28
+ keyEnd = i
41
29
  }
42
- key += item
43
30
  }
44
31
  } else {
45
32
  if (stackMap[item]) {
@@ -2484,12 +2484,6 @@ function processMpxTagName (el) {
2484
2484
  }
2485
2485
  }
2486
2486
 
2487
- function postProcessComponent (el, options) {
2488
- if (isComponentNode(el, options)) {
2489
- el.isComponent = true
2490
- }
2491
- }
2492
-
2493
2487
  function processElement (el, root, options, meta) {
2494
2488
  processAtMode(el)
2495
2489
  // 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
@@ -2581,8 +2575,6 @@ function closeElement (el, meta, options) {
2581
2575
  if (isReact(mode)) {
2582
2576
  postProcessForReact(el)
2583
2577
  postProcessIfReact(el)
2584
- // flag component for react
2585
- postProcessComponent(el, options)
2586
2578
  return
2587
2579
  }
2588
2580
  const pass = isNative || postProcessTemplate(el) || processingTemplate
@@ -2961,7 +2953,7 @@ function postProcessForDynamic (vnode) {
2961
2953
  }
2962
2954
 
2963
2955
  function postProcessAttrsDynamic (vnode, config) {
2964
- const exps = vnode.exps?.filter(v => v.attrName) || []
2956
+ const exps = (vnode.exps && vnode.exps.filter(v => v.attrName)) || []
2965
2957
  const expsMap = Object.fromEntries(exps.map(v => ([v.attrName, v])))
2966
2958
  const directives = Object.values(config.directive)
2967
2959
  if (vnode.attrsList && vnode.attrsList.length) {
@@ -59,7 +59,7 @@ function genNode (node) {
59
59
  const name = node.slot.name
60
60
  exp += `__getSlot(${name ? s(name) : ''})`
61
61
  } else {
62
- exp += `createElement(${node.isComponent || node.isBuiltIn ? `components[${node.is || s(node.tag)}]` : `getNativeComponent(${s(node.tag)})`}`
62
+ exp += `createElement(${`getComponent(${node.is || s(node.tag)})`}`
63
63
  if (node.isRoot) {
64
64
  exp += `, Object.assign({}, rootProps, {style: [${attrExpMap.style}, rootProps.style]})`
65
65
  } else if (node.attrsList.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.41-react.0",
3
+ "version": "2.9.41",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -85,5 +85,5 @@
85
85
  "engines": {
86
86
  "node": ">=14.14.0"
87
87
  },
88
- "gitHead": "1c9ae7527a257fad98f5536114e63415cea54271"
88
+ "gitHead": "0b3ee5d2c1b6c6e0af6a842eb4e12f4a1173c067"
89
89
  }