@mpxjs/webpack-plugin 2.10.15 → 2.10.16-beta.2

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 (89) hide show
  1. package/lib/dependencies/AppEntryDependency.js +2 -2
  2. package/lib/dependencies/DynamicEntryDependency.js +1 -1
  3. package/lib/dependencies/ImportDependency.js +102 -0
  4. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  5. package/lib/dependencies/ResolveDependency.js +1 -1
  6. package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
  7. package/lib/helpers.js +2 -0
  8. package/lib/index.js +51 -25
  9. package/lib/json-compiler/helper.js +72 -2
  10. package/lib/json-compiler/index.js +14 -54
  11. package/lib/json-compiler/plugin.js +2 -2
  12. package/lib/loader.js +6 -2
  13. package/lib/native-loader.js +6 -3
  14. package/lib/platform/json/wx/index.js +24 -29
  15. package/lib/platform/style/wx/index.js +8 -1
  16. package/lib/platform/template/wx/component-config/button.js +12 -3
  17. package/lib/platform/template/wx/component-config/camera.js +12 -0
  18. package/lib/platform/template/wx/component-config/component.js +31 -33
  19. package/lib/platform/template/wx/component-config/slider.js +12 -0
  20. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  21. package/lib/react/processJSON.js +39 -71
  22. package/lib/react/processStyles.js +3 -2
  23. package/lib/react/processTemplate.js +6 -6
  24. package/lib/react/script-helper.js +6 -16
  25. package/lib/react/style-helper.js +10 -2
  26. package/lib/resolver/AddEnvPlugin.js +13 -0
  27. package/lib/resolver/AddModePlugin.js +18 -0
  28. package/lib/runtime/components/react/context.ts +2 -0
  29. package/lib/runtime/components/react/dist/context.js +1 -0
  30. package/lib/runtime/components/react/dist/mpx-camera.jsx +102 -0
  31. package/lib/runtime/components/react/dist/mpx-image.jsx +81 -37
  32. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +19 -4
  33. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +3 -2
  34. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +9 -6
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  36. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  37. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  38. package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
  39. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  40. package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
  41. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  42. package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
  43. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  44. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  45. package/lib/runtime/components/react/mpx-camera.tsx +167 -0
  46. package/lib/runtime/components/react/mpx-image.tsx +89 -42
  47. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +31 -4
  48. package/lib/runtime/components/react/mpx-picker-view/index.tsx +4 -1
  49. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +19 -8
  50. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  51. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  52. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  53. package/lib/runtime/components/react/mpx-progress.tsx +26 -24
  54. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  55. package/lib/runtime/components/react/mpx-slider.tsx +444 -0
  56. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  57. package/lib/runtime/components/react/mpx-view.tsx +8 -11
  58. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  59. package/lib/runtime/components/react/utils.tsx +15 -6
  60. package/lib/runtime/components/web/mpx-input.vue +1 -1
  61. package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
  62. package/lib/runtime/components/web/mpx-video.vue +12 -1
  63. package/lib/runtime/optionProcessor.js +3 -1
  64. package/lib/runtime/optionProcessorReact.js +4 -2
  65. package/lib/script-setup-compiler/index.js +2 -2
  66. package/lib/style-compiler/index.js +3 -2
  67. package/lib/style-compiler/load-postcss-config.js +1 -1
  68. package/lib/style-compiler/plugins/trans-special.js +10 -2
  69. package/lib/style-compiler/strip-conditional-loader.js +155 -15
  70. package/lib/template-compiler/compiler.js +262 -61
  71. package/lib/template-compiler/gen-node-react.js +18 -6
  72. package/lib/template-compiler/index.js +6 -4
  73. package/lib/template-compiler/parse-exps.js +1 -1
  74. package/lib/utils/chain-assign.js +47 -0
  75. package/lib/utils/check-core-version-match.js +75 -15
  76. package/lib/utils/const.js +2 -1
  77. package/lib/utils/dom-tag-config.js +1 -1
  78. package/lib/utils/env.js +6 -1
  79. package/lib/utils/get-build-tag-component.js +35 -0
  80. package/lib/utils/pre-process-json.js +5 -0
  81. package/lib/web/processJSON.js +44 -16
  82. package/lib/web/processScript.js +1 -1
  83. package/lib/web/processTemplate.js +4 -4
  84. package/lib/web/script-helper.js +19 -9
  85. package/lib/wxs/pre-loader.js +5 -5
  86. package/lib/wxss/loader.js +1 -9
  87. package/package.json +14 -5
  88. package/LICENSE +0 -433
  89. package/lib/dependencies/ImportDependencyTemplate.js +0 -50
@@ -8,6 +8,7 @@ const { JSON_JS_EXT } = require('./utils/const')
8
8
  const getEntryName = require('./utils/get-entry-name')
9
9
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
10
10
  const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
11
+ const RecordModuleIdMapDependency = require('./dependencies/RecordModuleIdMapDependency')
11
12
  const preProcessJson = require('./utils/pre-process-json')
12
13
 
13
14
  // todo native-loader考虑与mpx-loader或加强复用,原生组件约等于4个区块都为src的.mpx文件
@@ -23,7 +24,9 @@ module.exports = function (content) {
23
24
  const loaderContext = this
24
25
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
25
26
  const filePath = this.resourcePath
26
- const moduleId = mpx.getModuleId(filePath)
27
+ const moduleId = mpx.getModuleId(filePath, false, this)
28
+ this._module.addPresentationalDependency(new RecordModuleIdMapDependency(moduleId, filePath))
29
+
27
30
  const { resourcePath, queryObj } = parseRequest(this.resource)
28
31
  const packageRoot = queryObj.packageRoot || mpx.currentPackageRoot
29
32
  const mode = mpx.mode
@@ -104,13 +107,13 @@ module.exports = function (content) {
104
107
 
105
108
  const emitWarning = (msg) => {
106
109
  this.emitWarning(
107
- new Error('[native-loader][' + this.resource + ']: ' + msg)
110
+ new Error('[Mpx json warning][native-loader][' + this.resource + ']: ' + msg)
108
111
  )
109
112
  }
110
113
 
111
114
  const emitError = (msg) => {
112
115
  this.emitError(
113
- new Error('[native-loader][' + this.resource + ']: ' + msg)
116
+ new Error('[Mpx json error][native-loader][' + this.resource + ']: ' + msg)
114
117
  )
115
118
  }
116
119
  let ctorType = pagesMap[resourcePath]
@@ -1,12 +1,9 @@
1
1
  const runRules = require('../../run-rules')
2
2
  const normalizeTest = require('../normalize-test')
3
3
  const changeKey = require('../change-key')
4
- const normalize = require('../../../utils/normalize')
5
4
  const { capitalToHyphen } = require('../../../utils/string')
6
5
  const { isOriginTag, isBuildInWebTag, isBuildInReactTag } = require('../../../utils/dom-tag-config')
7
-
8
- const mpxViewPath = normalize.lib('runtime/components/ali/mpx-view.mpx')
9
- const mpxTextPath = normalize.lib('runtime/components/ali/mpx-text.mpx')
6
+ const getBuildInTagComponent = require('../../../utils/get-build-tag-component')
10
7
 
11
8
  module.exports = function getSpec ({ warn, error }) {
12
9
  function print (mode, path, isError) {
@@ -46,28 +43,26 @@ module.exports = function getSpec ({ warn, error }) {
46
43
  }
47
44
 
48
45
  // 处理支付宝 componentPlaceholder 不支持 view、text 原生标签
49
- function aliComponentPlaceholderFallback (input) {
50
- // 处理 驼峰转连字符
51
- input = componentNameCapitalToHyphen('componentPlaceholder')(input)
46
+ // placeholder 中使用的内建组件转化为 mpx-xxx, 并在 usingComponents 填充
47
+ function fixComponentPlaceholder (input, { mode }) {
48
+ if (!input.componentPlaceholder) return input
49
+ if (mode === 'ali') {
50
+ // 处理 驼峰转连字符
51
+ input = componentNameCapitalToHyphen('componentPlaceholder')(input)
52
+ }
52
53
  const componentPlaceholder = input.componentPlaceholder
53
- const usingComponents = input.usingComponents || (input.usingComponents = {})
54
+ const usingComponents = input.usingComponents || {}
54
55
  for (const cph in componentPlaceholder) {
55
56
  const cur = componentPlaceholder[cph]
56
- const placeholderCompMatched = cur.match(/^(?:view|text)$/g)
57
- if (!Array.isArray(placeholderCompMatched)) continue
58
- let compName, compPath
59
- switch (placeholderCompMatched[0]) {
60
- case 'view':
61
- compName = 'mpx-view'
62
- compPath = mpxViewPath
63
- break
64
- case 'text':
65
- compName = 'mpx-text'
66
- compPath = mpxTextPath
67
- }
68
- usingComponents[compName] = compPath
69
- componentPlaceholder[cph] = compName
57
+ const comp = getBuildInTagComponent(mode, cur)
58
+ if (!comp || usingComponents[cur]) continue
59
+ const { name, resource } = comp
60
+ usingComponents[name] = resource
61
+ componentPlaceholder[cph] = name
70
62
  }
63
+
64
+ input.usingComponents = usingComponents
65
+ input.componentPlaceholder = componentPlaceholder
71
66
  return input
72
67
  }
73
68
 
@@ -172,7 +167,6 @@ module.exports = function getSpec ({ warn, error }) {
172
167
  },
173
168
  {
174
169
  test: 'componentPlaceholder',
175
- ali: aliComponentPlaceholderFallback,
176
170
  swan: deletePath(),
177
171
  jd: deletePath()
178
172
  },
@@ -190,6 +184,13 @@ module.exports = function getSpec ({ warn, error }) {
190
184
  ios: fixComponentName,
191
185
  android: fixComponentName,
192
186
  harmony: fixComponentName
187
+ },
188
+ {
189
+ ali: fixComponentPlaceholder,
190
+ web: fixComponentPlaceholder,
191
+ ios: fixComponentPlaceholder,
192
+ android: fixComponentPlaceholder,
193
+ harmony: fixComponentPlaceholder
193
194
  }
194
195
  ]
195
196
 
@@ -454,12 +455,6 @@ module.exports = function getSpec ({ warn, error }) {
454
455
  swan: getWindowRule(),
455
456
  tt: getWindowRule(),
456
457
  jd: getWindowRule()
457
- },
458
- {
459
- web: fixComponentName,
460
- ios: fixComponentName,
461
- android: fixComponentName,
462
- harmony: fixComponentName
463
458
  }
464
459
  ]
465
460
  }
@@ -315,7 +315,7 @@ module.exports = function getSpec ({ warn, error }) {
315
315
  switch (prop) {
316
316
  case bgPropMap.image: {
317
317
  // background-image 支持背景图/渐变/css var
318
- if (cssVariableExp.test(value) || urlExp.test(value) || linearExp.test(value)) {
318
+ if (cssVariableExp.test(value) || urlExp.test(value) || linearExp.test(value) || value === 'none') {
319
319
  return { prop, value }
320
320
  } else {
321
321
  error(`Value of ${prop} in ${selector} selector only support value <url()> or <linear-gradient()>, received ${value}, please check again!`)
@@ -359,6 +359,13 @@ module.exports = function getSpec ({ warn, error }) {
359
359
  error(`Property [${bgPropMap.all}] in ${selector} is abbreviated property and does not support CSS var`)
360
360
  return false
361
361
  }
362
+ // background: none
363
+ if (value === 'none') {
364
+ return [
365
+ { prop: bgPropMap.image, value },
366
+ { prop: bgPropMap.color, value: 'transparent' }
367
+ ]
368
+ }
362
369
  const bgMap = []
363
370
  const values = parseValues(value)
364
371
  values.forEach(item => {
@@ -31,13 +31,16 @@ module.exports = function ({ print }) {
31
31
  const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
32
32
  const wxPropValueLog = print({ platform: 'wx', tag: TAG_NAME, isError: false, type: 'value' })
33
33
  const iosValueLogError = print({ platform: 'ios', tag: TAG_NAME, isError: true, type: 'value' })
34
+ const iosValueLog = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'value' })
34
35
  const iosPropLog = print({ platform: 'ios', tag: TAG_NAME, isError: false })
35
36
  const iosEventLog = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'event' })
36
37
  const androidValueLogError = print({ platform: 'android', tag: TAG_NAME, isError: true, type: 'value' })
38
+ const androidValueLog = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'value' })
37
39
  const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
38
40
  const androidEventLog = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'event' })
39
41
 
40
42
  const harmonyValueLogError = print({ platform: 'harmony', tag: TAG_NAME, isError: true, type: 'value' })
43
+ const harmonyValueLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'value' })
41
44
  const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
42
45
  const harmonyEventLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'event' })
43
46
 
@@ -133,19 +136,25 @@ module.exports = function ({ print }) {
133
136
  ios ({ name, value }) {
134
137
  // TODO 此处open-type无其他属性支持了?
135
138
  const supported = ['share']
136
- if (!supported.includes(value)) {
139
+ if (isMustache(value)) {
140
+ iosValueLog({ name, value })
141
+ } else if (!supported.includes(value)) {
137
142
  iosValueLogError({ name, value })
138
143
  }
139
144
  },
140
145
  android ({ name, value }) {
141
146
  const supported = ['share']
142
- if (!supported.includes(value)) {
147
+ if (isMustache(value)) {
148
+ androidValueLog({ name, value })
149
+ } else if (!supported.includes(value)) {
143
150
  androidValueLogError({ name, value })
144
151
  }
145
152
  },
146
153
  harmony ({ name, value }) {
147
154
  const supported = ['share']
148
- if (!supported.includes(value)) {
155
+ if (isMustache(value)) {
156
+ harmonyValueLog({ name, value })
157
+ } else if (!supported.includes(value)) {
149
158
  harmonyValueLogError({ name, value })
150
159
  }
151
160
  }
@@ -15,6 +15,18 @@ module.exports = function ({ print }) {
15
15
  const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
16
16
  return {
17
17
  test: TAG_NAME,
18
+ ios (tag, { el }) {
19
+ el.isBuiltIn = true
20
+ return 'mpx-camera'
21
+ },
22
+ android (tag, { el }) {
23
+ el.isBuiltIn = true
24
+ return 'mpx-camera'
25
+ },
26
+ harmony (tag, { el }) {
27
+ el.isBuiltIn = true
28
+ return 'mpx-camera'
29
+ },
18
30
  props: [
19
31
  {
20
32
  test: 'mode',
@@ -1,43 +1,41 @@
1
- const { parseMustache } = require('../../../../template-compiler/compiler')
2
- const normalize = require('../../../../utils/normalize')
3
1
  const TAG_NAME = 'component'
4
2
 
5
- /** is 属性格式化为中划线(-)连接 */
6
- const formatPropIs = (obj, data) => {
7
- const parsed = parseMustache(obj.value)
8
- let value = parsed.result
9
- if (parsed.hasBinding) value = value.slice(1, -1)
10
- const el = data.el
11
- if (el) {
12
- const injectWxsProp = {
13
- injectWxsPath: '~' + normalize.lib('runtime/utils.wxs'),
14
- injectWxsModuleName: '__wxsUtils__'
15
- }
16
- if (el.injectWxsProps && Array.isArray(el.injectWxsProps)) {
17
- el.injectWxsProps.push(injectWxsProp)
18
- } else {
19
- el.injectWxsProps = [injectWxsProp]
20
- }
21
- }
22
- return {
23
- name: 'is',
24
- value: `{{__wxsUtils__.humpToLine(${value})}}`
25
- }
26
- }
3
+ /** is 属性格式化为中划线(-)连接 (弃用,新方案:https://github.com/didi/mpx/pull/2228) */
4
+ // const formatPropIs = (obj, data) => {
5
+ // const parsed = parseMustache(obj.value)
6
+ // let value = parsed.result
7
+ // if (parsed.hasBinding) value = value.slice(1, -1)
8
+ // const el = data.el
9
+ // if (el) {
10
+ // const injectWxsProp = {
11
+ // injectWxsPath: '~' + normalize.lib('runtime/utils.wxs'),
12
+ // injectWxsModuleName: '__wxsUtils__'
13
+ // }
14
+ // if (el.injectWxsProps && Array.isArray(el.injectWxsProps)) {
15
+ // el.injectWxsProps.push(injectWxsProp)
16
+ // } else {
17
+ // el.injectWxsProps = [injectWxsProp]
18
+ // }
19
+ // }
20
+ // return {
21
+ // name: 'is',
22
+ // value: `{{__wxsUtils__.humpToLine(${value})}}`
23
+ // }
24
+ // }
27
25
 
28
26
  module.exports = function () {
29
27
  return {
30
28
  test: TAG_NAME,
31
29
  props: [
32
- {
33
- test: 'is',
34
- ali (obj, data) {
35
- return formatPropIs(obj, data)
36
- },
37
- swan (obj, data) {
38
- return formatPropIs(obj, data)
39
- }
40
- }
30
+ // {
31
+ // test: 'is',
32
+ // ali (obj, data) {
33
+ // return formatPropIs(obj, data)
34
+ // },
35
+ // swan (obj, data) {
36
+ // return formatPropIs(obj, data)
37
+ // }
38
+ // }
41
39
  ]
42
40
  }
43
41
  }
@@ -8,6 +8,18 @@ module.exports = function ({ print }) {
8
8
  el.isBuiltIn = true
9
9
  return 'mpx-slider'
10
10
  },
11
+ android (tag, { el }) {
12
+ el.isBuiltIn = true
13
+ return 'mpx-slider'
14
+ },
15
+ harmony (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'mpx-slider'
18
+ },
19
+ ios (tag, { el }) {
20
+ el.isBuiltIn = true
21
+ return 'mpx-slider'
22
+ },
11
23
  props: [
12
24
  {
13
25
  test: /^color$/,
@@ -11,7 +11,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
11
11
  // 快应用不支持的标签集合
12
12
  const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
13
13
  // RN不支持的标签集合
14
- const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'slider', 'audio', 'camera', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
14
+ const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'audio', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
15
15
 
16
16
  /**
17
17
  * @param {function(object): function} print
@@ -12,11 +12,8 @@ const { transSubpackage } = require('../utils/trans-async-sub-rules')
12
12
  const createJSONHelper = require('../json-compiler/helper')
13
13
  const getRulesRunner = require('../platform/index')
14
14
  const { RESOLVE_IGNORED_ERR } = require('../utils/const')
15
- const normalize = require('../utils/normalize')
16
15
  const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
17
16
  const RecordPageConfigsMapDependency = require('../dependencies/RecordPageConfigsMapDependency')
18
- const mpxViewPath = normalize.lib('runtime/components/react/dist/mpx-view.jsx')
19
- const mpxTextPath = normalize.lib('runtime/components/react/dist/mpx-text.jsx')
20
17
 
21
18
  module.exports = function (jsonContent, {
22
19
  loaderContext,
@@ -42,23 +39,38 @@ module.exports = function (jsonContent, {
42
39
 
43
40
  const emitWarning = (msg) => {
44
41
  loaderContext.emitWarning(
45
- new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
42
+ new Error('[Mpx json warning][' + loaderContext.resource + ']: ' + msg)
46
43
  )
47
44
  }
48
45
 
49
46
  const emitError = (msg) => {
50
47
  loaderContext.emitError(
51
- new Error('[json compiler][' + loaderContext.resource + ']: ' + msg)
48
+ new Error('[Mpx json error][' + loaderContext.resource + ']: ' + msg)
52
49
  )
53
50
  }
54
51
 
55
52
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
56
53
 
54
+ function fillInComponentsMap (name, entry, tarRoot) {
55
+ const { resource, outputPath } = entry
56
+ const { resourcePath } = parseRequest(resource)
57
+ componentsMap[resourcePath] = outputPath
58
+ loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
59
+ localComponentsMap[name] = {
60
+ resource: addQuery(resource, {
61
+ isComponent: true,
62
+ outputPath
63
+ }),
64
+ async: tarRoot
65
+ }
66
+ }
67
+
57
68
  const {
58
69
  isUrlRequest,
59
70
  urlToRequest,
60
71
  processPage,
61
- processComponent
72
+ processComponent,
73
+ processPlaceholder
62
74
  } = createJSONHelper({
63
75
  loaderContext,
64
76
  emitWarning,
@@ -137,45 +149,6 @@ module.exports = function (jsonContent, {
137
149
  isShow: true
138
150
  }
139
151
 
140
- const fillInComponentPlaceholder = (name, placeholder, placeholderEntry) => {
141
- const componentPlaceholder = jsonObj.componentPlaceholder || {}
142
- if (componentPlaceholder[name]) return
143
- componentPlaceholder[name] = placeholder
144
- jsonObj.componentPlaceholder = componentPlaceholder
145
- if (placeholderEntry && !jsonObj.usingComponents[placeholder]) jsonObj.usingComponents[placeholder] = placeholderEntry
146
- }
147
-
148
- const fillInComponentsMap = (name, entry, tarRoot) => {
149
- const { resource, outputPath } = entry
150
- const { resourcePath } = parseRequest(resource)
151
- tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
152
- componentsMap[resourcePath] = outputPath
153
- loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
154
- localComponentsMap[name] = {
155
- resource: addQuery(resource, {
156
- isComponent: true,
157
- outputPath
158
- }),
159
- async: tarRoot
160
- }
161
- }
162
-
163
- const normalizePlaceholder = (placeholder) => {
164
- if (typeof placeholder === 'string') {
165
- const placeholderMap = mode === 'ali'
166
- ? {
167
- view: { name: 'mpx-view', resource: mpxViewPath },
168
- text: { name: 'mpx-text', resource: mpxTextPath }
169
- }
170
- : {}
171
- placeholder = placeholderMap[placeholder] || { name: placeholder }
172
- }
173
- if (!placeholder.name) {
174
- emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
175
- }
176
- return placeholder
177
- }
178
-
179
152
  const processTabBar = (tabBar, callback) => {
180
153
  if (tabBar) {
181
154
  tabBar = Object.assign({}, defaultTabbar, tabBar)
@@ -345,38 +318,34 @@ module.exports = function (jsonContent, {
345
318
 
346
319
  const processComponents = (components, context, callback) => {
347
320
  if (components) {
321
+ const asyncComponents = []
322
+ const resolveResourcePathMap = new Map()
348
323
  async.eachOf(components, (component, name, callback) => {
349
- processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder } = {}) => {
324
+ processComponent(component, context, {}, (err, entry = {}, { tarRoot, placeholder, resourcePath } = {}) => {
350
325
  if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
351
- fillInComponentsMap(name, entry, tarRoot)
352
326
  const { relativePath } = entry
353
327
 
354
- if (tarRoot) {
328
+ tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
329
+
330
+ resolveResourcePathMap.set(name, resourcePath)
331
+ if (tarRoot) asyncComponents.push({ name, tarRoot, placeholder, relativePath })
332
+
333
+ fillInComponentsMap(name, entry, tarRoot)
334
+ callback()
335
+ })
336
+ }, (err) => {
337
+ if (err) return callback(err)
338
+ async.each(asyncComponents, ({ name, tarRoot, placeholder, relativePath }, callback) => {
339
+ processPlaceholder({ jsonObj, context, name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, (err, placeholder) => {
340
+ if (err) return callback(err)
355
341
  if (placeholder) {
356
- placeholder = normalizePlaceholder(placeholder)
357
- if (placeholder.resource) {
358
- processComponent(placeholder.resource, projectRoot, { relativePath }, (err, entry) => {
359
- if (err) return callback(err)
360
- fillInComponentPlaceholder(name, placeholder.name, entry)
361
- fillInComponentsMap(placeholder.name, entry, '')
362
- callback()
363
- })
364
- } else {
365
- fillInComponentPlaceholder(name, placeholder.name)
366
- callback()
367
- }
368
- } else {
369
- if (!jsonObj.componentPlaceholder || !jsonObj.componentPlaceholder[name]) {
370
- const errMsg = `componentPlaceholder of "${name}" doesn't exist! \n\r`
371
- emitError(errMsg)
372
- }
373
- callback()
342
+ const { name, entry } = placeholder
343
+ fillInComponentsMap(name, entry, '')
374
344
  }
375
- } else {
376
345
  callback()
377
- }
378
- })
379
- }, callback)
346
+ })
347
+ }, callback)
348
+ })
380
349
  } else {
381
350
  callback()
382
351
  }
@@ -394,7 +363,6 @@ module.exports = function (jsonContent, {
394
363
  callback()
395
364
  }
396
365
  }
397
-
398
366
  async.parallel([
399
367
  (callback) => {
400
368
  // 添加首页标识
@@ -15,12 +15,12 @@ module.exports = function (styles, {
15
15
  if (styles.length) {
16
16
  const warn = (msg) => {
17
17
  loaderContext.emitWarning(
18
- new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
18
+ new Error('[Mpx style warning][' + loaderContext.resource + ']: ' + msg)
19
19
  )
20
20
  }
21
21
  const error = (msg) => {
22
22
  loaderContext.emitError(
23
- new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
23
+ new Error('[Mpx style error][' + loaderContext.resource + ']: ' + msg)
24
24
  )
25
25
  }
26
26
  const { mode, srcMode } = loaderContext.getMpx()
@@ -52,6 +52,7 @@ module.exports = function (styles, {
52
52
  filename: loaderContext.resourcePath,
53
53
  mode,
54
54
  srcMode,
55
+ ctorType,
55
56
  warn,
56
57
  error
57
58
  })
@@ -46,22 +46,22 @@ module.exports = function (template, {
46
46
  if (template) {
47
47
  // 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
48
48
  if (template.src) {
49
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
49
+ return callback(new Error('[Mpx template error][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
50
50
  }
51
51
  if (template.lang) {
52
- return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans react native mode temporarily, we will support it in the future!'))
52
+ return callback(new Error('[Mpx template error][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans react native mode temporarily, we will support it in the future!'))
53
53
  }
54
54
 
55
55
  if (template.content) {
56
56
  const templateSrcMode = template.mode || srcMode
57
57
  const warn = (msg) => {
58
58
  loaderContext.emitWarning(
59
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
59
+ new Error('[Mpx template warning][' + loaderContext.resource + ']: ' + msg)
60
60
  )
61
61
  }
62
62
  const error = (msg) => {
63
63
  loaderContext.emitError(
64
- new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
64
+ new Error('[mpx template error][' + loaderContext.resource + ']: ' + msg)
65
65
  )
66
66
  }
67
67
  const { root, meta } = templateCompiler.parse(template.content, {
@@ -113,7 +113,7 @@ module.exports = function (template, {
113
113
  output += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
114
114
  }
115
115
 
116
- const rawCode = genNode(root)
116
+ const rawCode = genNode(root, true)
117
117
  if (rawCode) {
118
118
  try {
119
119
  const ignoreMap = Object.assign({
@@ -130,7 +130,7 @@ module.exports = function (template, {
130
130
  return ${bindResult.code}
131
131
  };\n`
132
132
  } catch (e) {
133
- error(`Invalid render function generated by the template, please check!
133
+ error(`[Mpx template error]: Invalid render function generated by the template, please check!
134
134
  Error code:
135
135
  ${rawCode}
136
136
  Error Detail:
@@ -4,16 +4,11 @@ const parseRequest = require('../utils/parse-request')
4
4
  const shallowStringify = require('../utils/shallow-stringify')
5
5
  const normalize = require('../utils/normalize')
6
6
  const addQuery = require('../utils/add-query')
7
- const { isBuildInReactTag } = require('../utils/dom-tag-config')
8
7
 
9
8
  function stringifyRequest (loaderContext, request) {
10
9
  return loaderUtils.stringifyRequest(loaderContext, request)
11
10
  }
12
11
 
13
- function getBuiltInComponentRequest (component) {
14
- return JSON.stringify(addQuery(`@mpxjs/webpack-plugin/lib/runtime/components/react/dist/${component}`, { isComponent: true }))
15
- }
16
-
17
12
  function getAsyncChunkName (chunkName) {
18
13
  if (chunkName && typeof chunkName !== 'boolean') {
19
14
  return `/* webpackChunkName: "${chunkName}/index" */`
@@ -26,8 +21,8 @@ function getAsyncSuspense (type, moduleId, componentRequest, componentName, chun
26
21
  type: ${JSON.stringify(type)},
27
22
  moduleId: ${JSON.stringify(moduleId)},
28
23
  chunkName: ${JSON.stringify(chunkName)},
29
- getFallback: ${getFallback},
30
- getLoading: ${getLoading},
24
+ ${getFallback ? `getFallback: ${getFallback},` : ''}
25
+ ${getLoading ? `getLoading: ${getLoading},` : ''}
31
26
  getChildren () {
32
27
  return import(${getAsyncChunkName(chunkName)}${componentRequest}).then(function (res) {
33
28
  return getComponent(res, {displayName: ${JSON.stringify(componentName)}})
@@ -95,22 +90,17 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
95
90
  if (placeholder) {
96
91
  if (localComponentsMap[placeholder]) {
97
92
  const placeholderCfg = localComponentsMap[placeholder]
98
- const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
99
93
  if (placeholderCfg.async) {
100
94
  loaderContext.emitWarning(
101
95
  new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
102
96
  )
103
97
  }
98
+ const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
104
99
  getFallback = getComponentGetter(getComponent(placeholderRequest, placeholder))
105
100
  } else {
106
- const tag = `mpx-${placeholder}`
107
- if (isBuildInReactTag(tag)) {
108
- getFallback = getComponentGetter(getBuiltInComponent(getBuiltInComponentRequest(tag)))
109
- } else {
110
- loaderContext.emitError(
111
- new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component, please check!`)
112
- )
113
- }
101
+ loaderContext.emitError(
102
+ new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} is not built-in component or custom component, please check!`)
103
+ )
114
104
  }
115
105
  } else {
116
106
  loaderContext.emitError(
@@ -1,5 +1,6 @@
1
1
  const postcss = require('postcss')
2
2
  const selectorParser = require('postcss-selector-parser')
3
+ const { MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
3
4
  const getRulesRunner = require('../platform/index')
4
5
  const dash2hump = require('../utils/hump-dash').dash2hump
5
6
  const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh)\s*$/
@@ -7,8 +8,8 @@ const numberRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
7
8
  const hairlineRegExp = /^\s*hairlineWidth\s*$/
8
9
  const varRegExp = /^--/
9
10
  const cssPrefixExp = /^-(webkit|moz|ms|o)-/
10
- function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
11
- const classMap = {}
11
+ function getClassMap ({ content, filename, mode, srcMode, ctorType, warn, error }) {
12
+ const classMap = ctorType === 'page' ? { [MPX_TAG_PAGE_SELECTOR]: { flex: 1 } } : {}
12
13
 
13
14
  const root = postcss.parse(content, {
14
15
  from: filename
@@ -36,6 +37,13 @@ function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
36
37
  error
37
38
  })
38
39
 
40
+ // 目前所有 AtRule 只支持 @media,其他全部给出错误提示
41
+ root.walkAtRules(rule => {
42
+ if (rule.name !== 'media') {
43
+ warn(`Only @media rule is supported in react native mode temporarily, but got @${rule.name}`)
44
+ }
45
+ })
46
+
39
47
  root.walkRules(rule => {
40
48
  const classMapValue = {}
41
49
  rule.walkDecls(({ prop, value }) => {