@mpxjs/webpack-plugin 2.9.66 → 2.9.69

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 (112) hide show
  1. package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
  2. package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
  3. package/lib/index.js +29 -8
  4. package/lib/json-compiler/index.js +2 -11
  5. package/lib/loader.js +24 -45
  6. package/lib/native-loader.js +49 -64
  7. package/lib/platform/json/wx/index.js +3 -10
  8. package/lib/platform/style/wx/index.js +15 -10
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/index.js +4 -3
  12. package/lib/react/processJSON.js +5 -13
  13. package/lib/react/processMainScript.js +7 -3
  14. package/lib/react/processScript.js +3 -4
  15. package/lib/react/processStyles.js +14 -4
  16. package/lib/react/processTemplate.js +2 -2
  17. package/lib/resolver/AddModePlugin.js +20 -7
  18. package/lib/runtime/components/react/context.ts +2 -0
  19. package/lib/runtime/components/react/dist/context.js +1 -0
  20. package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
  21. package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
  22. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  31. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
  32. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
  34. package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
  35. package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
  37. package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
  38. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
  39. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
  40. package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
  41. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
  42. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
  43. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
  44. package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
  45. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
  46. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +49 -29
  47. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
  48. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
  49. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
  50. package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
  51. package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
  52. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  53. package/lib/runtime/components/react/dist/mpx-view.jsx +46 -27
  54. package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
  55. package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
  56. package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
  57. package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
  58. package/lib/runtime/components/react/dist/utils.jsx +66 -6
  59. package/lib/runtime/components/react/getInnerListeners.ts +3 -16
  60. package/lib/runtime/components/react/mpx-button.tsx +42 -9
  61. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  62. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  63. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  64. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  65. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  66. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  67. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  68. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  69. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  70. package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
  71. package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
  72. package/lib/runtime/components/react/mpx-form.tsx +42 -34
  73. package/lib/runtime/components/react/mpx-icon.tsx +1 -1
  74. package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
  75. package/lib/runtime/components/react/mpx-input.tsx +68 -66
  76. package/lib/runtime/components/react/mpx-label.tsx +11 -8
  77. package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
  78. package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
  79. package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
  80. package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
  81. package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
  82. package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
  83. package/lib/runtime/components/react/mpx-radio.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
  85. package/lib/runtime/components/react/mpx-scroll-view.tsx +81 -36
  86. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
  87. package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
  88. package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
  89. package/lib/runtime/components/react/mpx-switch.tsx +10 -2
  90. package/lib/runtime/components/react/mpx-text.tsx +1 -1
  91. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  92. package/lib/runtime/components/react/mpx-view.tsx +58 -28
  93. package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
  94. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  95. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  96. package/lib/runtime/components/react/types/common.ts +2 -0
  97. package/lib/runtime/components/react/types/global.d.ts +2 -0
  98. package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
  99. package/lib/runtime/components/react/useNodesRef.ts +1 -0
  100. package/lib/runtime/components/react/utils.tsx +94 -8
  101. package/lib/runtime/optionProcessorReact.js +0 -15
  102. package/lib/runtime/swanHelper.wxs +1 -1
  103. package/lib/style-compiler/index.js +1 -1
  104. package/lib/style-compiler/plugins/scope-id.js +1 -0
  105. package/lib/template-compiler/compiler.js +47 -16
  106. package/lib/template-compiler/gen-node-react.js +2 -2
  107. package/lib/template-compiler/index.js +4 -4
  108. package/lib/utils/pre-process-json.js +113 -0
  109. package/lib/web/index.js +5 -4
  110. package/lib/web/processJSON.js +5 -13
  111. package/lib/web/processTemplate.js +2 -2
  112. package/package.json +5 -4
@@ -1,11 +1,11 @@
1
1
  const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
2
  const makeSerializable = require('webpack/lib/util/makeSerializable')
3
- const addQuery = require('../utils/add-query')
4
3
 
5
4
  class RecordGlobalComponentsDependency extends NullDependency {
6
- constructor (usingComponents, context) {
5
+ constructor (globalComponents, globalComponentsInfo, context) {
7
6
  super()
8
- this.usingComponents = usingComponents
7
+ this.globalComponents = globalComponents
8
+ this.globalComponentsInfo = globalComponentsInfo
9
9
  this.context = context
10
10
  }
11
11
 
@@ -15,26 +15,25 @@ class RecordGlobalComponentsDependency extends NullDependency {
15
15
 
16
16
  mpxAction (module, compilation, callback) {
17
17
  const mpx = compilation.__mpx__
18
- const { usingComponents, context } = this
19
- Object.keys(usingComponents).forEach((key) => {
20
- const request = usingComponents[key]
21
- mpx.usingComponents[key] = addQuery(request, {
22
- context
23
- })
24
- })
18
+ const { globalComponents, globalComponentsInfo } = this
19
+
20
+ mpx.globalComponents = globalComponents
21
+ mpx.globalComponentsInfo = globalComponentsInfo
25
22
  return callback()
26
23
  }
27
24
 
28
25
  serialize (context) {
29
26
  const { write } = context
30
- write(this.usingComponents)
27
+ write(this.globalComponents)
28
+ write(this.globalComponentsInfo)
31
29
  write(this.context)
32
30
  super.serialize(context)
33
31
  }
34
32
 
35
33
  deserialize (context) {
36
34
  const { read } = context
37
- this.usingComponents = read()
35
+ this.globalComponents = read()
36
+ this.globalComponentsInfo = read()
38
37
  this.context = read()
39
38
  super.deserialize(context)
40
39
  }
@@ -23,7 +23,7 @@ class RecordRuntimeInfoDependency extends NullDependency {
23
23
  template: {},
24
24
  json: {},
25
25
  style: [],
26
- moduleId: '_' + mpx.pathHash(this.resourcePath)
26
+ moduleId: mpx.getModuleId(this.resourcePath)
27
27
  }
28
28
 
29
29
  const infoConfig = componentInfo[this.blockType]
package/lib/index.js CHANGED
@@ -63,7 +63,7 @@ const async = require('async')
63
63
  const { parseQuery } = require('loader-utils')
64
64
  const stringifyLoadersAndResource = require('./utils/stringify-loaders-resource')
65
65
  const emitFile = require('./utils/emit-file')
66
- const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
66
+ const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE, MPX_APP_MODULE_ID } = require('./utils/const')
67
67
  const isEmptyObject = require('./utils/is-empty-object')
68
68
  const DynamicPlugin = require('./resolver/DynamicPlugin')
69
69
  const { isReact, isWeb } = require('./utils/env')
@@ -159,7 +159,6 @@ class MpxWebpackPlugin {
159
159
  return externalsMap[external] || external
160
160
  })
161
161
  options.projectRoot = options.projectRoot || process.cwd()
162
- options.projectName = options.projectName || 'AwesomeProject'
163
162
  options.forceUsePageCtor = options.forceUsePageCtor || false
164
163
  options.postcssInlineConfig = options.postcssInlineConfig || {}
165
164
  options.transRpxRules = options.transRpxRules || null
@@ -180,6 +179,7 @@ class MpxWebpackPlugin {
180
179
  include: () => true
181
180
  }
182
181
  options.customOutputPath = options.customOutputPath || null
182
+ options.customComponentModuleId = options.customComponentModuleId || null
183
183
  options.nativeConfig = Object.assign({
184
184
  cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
185
185
  }, options.nativeConfig)
@@ -348,7 +348,19 @@ class MpxWebpackPlugin {
348
348
  compiler.options.node.global = true
349
349
  }
350
350
 
351
- const addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
351
+ const addModeOptions = {
352
+ fileConditionRules: this.options.fileConditionRules
353
+ }
354
+ const mode = this.options.mode
355
+ if (mode === 'web' || mode === 'ios' || mode === 'android' || mode === 'harmony') {
356
+ // 'web' | 'ios' | 'android' | 'harmony' 下,使用implicitMode强制进行平台转换
357
+ addModeOptions.implicitMode = true
358
+ }
359
+ if (mode === 'android' || mode === 'harmony') {
360
+ // 'android' | 'harmony' 下,使用 mode = 'ios' 进行兼容兜底
361
+ addModeOptions.defaultMode = 'ios'
362
+ }
363
+ const addModePlugin = new AddModePlugin('before-file', this.options.mode, addModeOptions, 'file')
352
364
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
353
365
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
354
366
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
@@ -673,7 +685,8 @@ class MpxWebpackPlugin {
673
685
  assetsModulesMap: new Map(),
674
686
  // 记录与asset相关联的ast,用于体积分析和esCheck,避免重复parse
675
687
  assetsASTsMap: new Map(),
676
- usingComponents: {},
688
+ globalComponents: {},
689
+ globalComponentsInfo: {},
677
690
  // todo es6 map读写性能高于object,之后会逐步替换
678
691
  wxsAssetsCache: new Map(),
679
692
  addEntryPromiseMap: new Map(),
@@ -686,7 +699,6 @@ class MpxWebpackPlugin {
686
699
  env: this.options.env,
687
700
  externalClasses: this.options.externalClasses,
688
701
  projectRoot: this.options.projectRoot,
689
- projectName: this.options.projectName,
690
702
  autoScopeRules: this.options.autoScopeRules,
691
703
  autoVirtualHostRules: this.options.autoVirtualHostRules,
692
704
  customTextRules: this.options.customTextRules,
@@ -740,6 +752,15 @@ class MpxWebpackPlugin {
740
752
  compilation.addEntry(compiler.context, dep, { name }, callback)
741
753
  return dep
742
754
  },
755
+ getModuleId: (filePath, isApp = false) => {
756
+ if (isApp) return MPX_APP_MODULE_ID
757
+ const customComponentModuleId = this.options.customComponentModuleId
758
+ if (typeof customComponentModuleId === 'function') {
759
+ const customModuleId = customComponentModuleId(filePath)
760
+ if (customModuleId) return customModuleId
761
+ }
762
+ return '_' + mpx.pathHash(filePath)
763
+ },
743
764
  getEntryNode: (module, type) => {
744
765
  const entryNodeModulesMap = mpx.entryNodeModulesMap
745
766
  let entryNode = entryNodeModulesMap.get(module)
@@ -759,7 +780,7 @@ class MpxWebpackPlugin {
759
780
  const hash = mpx.pathHash(resourcePath)
760
781
  const customOutputPath = this.options.customOutputPath
761
782
  if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
762
- if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext).replace(/^\//, '')
783
+ if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext, resourcePath).replace(/^\//, '')
763
784
  if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
764
785
  return path.join(type, name + hash + ext)
765
786
  },
@@ -1814,8 +1835,8 @@ try {
1814
1835
  }
1815
1836
  createData.resource = addQuery(createData.resource, { mpx: MPX_PROCESSED_FLAG }, true)
1816
1837
  }
1817
-
1818
- if (isWeb(mpx.mode)) {
1838
+ // mpxStyleOptions 为 mpx style 文件的标识,避免 Vue 文件插入 styleCompiler 后导致 vue scoped 样式隔离失效
1839
+ if (isWeb(mpx.mode) && queryObj.mpxStyleOptions) {
1819
1840
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1820
1841
  const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
1821
1842
  let cssLoaderIndex = -1
@@ -10,7 +10,6 @@ const addQuery = require('../utils/add-query')
10
10
  const getJSONContent = require('../utils/get-json-content')
11
11
  const createHelpers = require('../helpers')
12
12
  const createJSONHelper = require('./helper')
13
- const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
14
13
  const RecordIndependentDependency = require('../dependencies/RecordIndependentDependency')
15
14
  const RecordRuntimeInfoDependency = require('../dependencies/RecordRuntimeInfoDependency')
16
15
  const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR, JSON_JS_EXT } = require('../utils/const')
@@ -208,8 +207,8 @@ module.exports = function (content) {
208
207
  warn: emitWarning,
209
208
  error: emitError,
210
209
  data: {
211
- // polyfill global usingComponents & record globalComponents
212
- globalComponents: mpx.usingComponents
210
+ // polyfill global usingComponents
211
+ globalComponents: mpx.globalComponents
213
212
  }
214
213
  }
215
214
  if (!isApp) {
@@ -222,14 +221,6 @@ module.exports = function (content) {
222
221
  rulesRunner(json)
223
222
  }
224
223
 
225
- if (isApp) {
226
- Object.assign(mpx.usingComponents, json.usingComponents)
227
- // 在 rulesRunner 运行后保存全局注册组件
228
- // todo 其余地方在使用mpx.usingComponents时存在缓存问题,要规避该问题需要在所有使用mpx.usingComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
229
- // todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
230
- this._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, this.context))
231
- }
232
-
233
224
  const processComponents = (components, context, callback) => {
234
225
  if (components) {
235
226
  async.eachOf(components, (component, name, callback) => {
package/lib/loader.js CHANGED
@@ -1,11 +1,9 @@
1
- const JSON5 = require('json5')
2
1
  const parseComponent = require('./parser')
3
2
  const createHelpers = require('./helpers')
4
3
  const parseRequest = require('./utils/parse-request')
5
4
  const { matchCondition } = require('./utils/match-condition')
6
5
  const addQuery = require('./utils/add-query')
7
6
  const async = require('async')
8
- const getJSONContent = require('./utils/get-json-content')
9
7
  const normalize = require('./utils/normalize')
10
8
  const getEntryName = require('./utils/get-entry-name')
11
9
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
@@ -13,12 +11,11 @@ const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDep
13
11
  const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
14
12
  const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
15
13
  const tsWatchRunLoaderFilter = require('./utils/ts-loader-watch-run-loader-filter')
16
- const { MPX_APP_MODULE_ID } = require('./utils/const')
17
14
  const { isReact } = require('./utils/env')
15
+ const preProcessJson = require('./utils/pre-process-json')
18
16
  const path = require('path')
19
17
  const processWeb = require('./web')
20
18
  const processReact = require('./react')
21
- const getRulesRunner = require('./platform')
22
19
  const genMpxCustomElement = require('./runtime-render/gen-mpx-custom-element')
23
20
 
24
21
  module.exports = function (content) {
@@ -89,7 +86,7 @@ module.exports = function (content) {
89
86
  const loaderContext = this
90
87
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
91
88
  const filePath = this.resourcePath
92
- const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : '_' + mpx.pathHash(filePath)
89
+ const moduleId = mpx.getModuleId(resourcePath, ctorType === 'app')
93
90
 
94
91
  const parts = parseComponent(content, {
95
92
  filePath,
@@ -106,55 +103,36 @@ module.exports = function (content) {
106
103
 
107
104
  async.waterfall([
108
105
  (callback) => {
109
- getJSONContent(parts.json || {}, null, loaderContext, (err, content) => {
106
+ preProcessJson({
107
+ json: parts.json || {},
108
+ srcMode,
109
+ emitWarning,
110
+ emitError,
111
+ ctorType,
112
+ resourcePath,
113
+ loaderContext
114
+ }, (err, jsonInfo) => {
110
115
  if (err) return callback(err)
111
- if (parts.json) parts.json.content = content
112
- callback()
116
+ callback(null, jsonInfo)
113
117
  })
114
118
  },
115
- (callback) => {
119
+ (jsonInfo, callback) => {
120
+ const {
121
+ componentPlaceholder,
122
+ componentGenerics,
123
+ usingComponentsInfo,
124
+ jsonContent
125
+ } = jsonInfo
116
126
  const hasScoped = parts.styles.some(({ scoped }) => scoped) || autoScope
117
127
  const templateAttrs = parts.template && parts.template.attrs
118
128
  const hasComment = templateAttrs && templateAttrs.comments
119
129
  const isNative = false
120
130
 
121
- let usingComponents = [].concat(Object.keys(mpx.usingComponents))
122
- let componentPlaceholder = []
123
- let componentGenerics = {}
124
-
125
- if (parts.json && parts.json.content) {
126
- const rulesRunnerOptions = {
127
- mode,
128
- srcMode,
129
- type: 'json',
130
- waterfall: true,
131
- warn: emitWarning,
132
- error: emitError
133
- }
134
- if (ctorType !== 'app') {
135
- rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
136
- }
137
- const rulesRunner = getRulesRunner(rulesRunnerOptions)
138
- try {
139
- const ret = JSON5.parse(parts.json.content)
140
- if (rulesRunner) rulesRunner(ret)
141
- if (ret.usingComponents) {
142
- usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
143
- }
144
- if (ret.componentPlaceholder) {
145
- componentPlaceholder = componentPlaceholder.concat(Object.values(ret.componentPlaceholder))
146
- }
147
- if (ret.componentGenerics) {
148
- componentGenerics = Object.assign({}, ret.componentGenerics)
149
- }
150
- } catch (e) {
151
- return callback(e)
152
- }
153
- }
154
131
  // 处理mode为web时输出vue格式文件
155
132
  if (mode === 'web') {
156
133
  return processWeb({
157
134
  parts,
135
+ jsonContent,
158
136
  loaderContext,
159
137
  pagesMap,
160
138
  componentsMap,
@@ -166,7 +144,7 @@ module.exports = function (content) {
166
144
  hasScoped,
167
145
  hasComment,
168
146
  isNative,
169
- usingComponents,
147
+ usingComponentsInfo: JSON.stringify(usingComponentsInfo),
170
148
  componentGenerics,
171
149
  autoScope,
172
150
  callback
@@ -176,6 +154,7 @@ module.exports = function (content) {
176
154
  if (isReact(mode)) {
177
155
  return processReact({
178
156
  parts,
157
+ jsonContent,
179
158
  loaderContext,
180
159
  pagesMap,
181
160
  componentsMap,
@@ -187,7 +166,7 @@ module.exports = function (content) {
187
166
  hasScoped,
188
167
  hasComment,
189
168
  isNative,
190
- usingComponents,
169
+ usingComponentsInfo: JSON.stringify(usingComponentsInfo),
191
170
  componentGenerics,
192
171
  autoScope,
193
172
  callback
@@ -255,7 +234,7 @@ module.exports = function (content) {
255
234
  isNative,
256
235
  ctorType,
257
236
  moduleId,
258
- usingComponents,
237
+ usingComponentsInfo: JSON.stringify(usingComponentsInfo),
259
238
  componentPlaceholder
260
239
  // 添加babel处理渲染函数中可能包含的...展开运算符
261
240
  // 由于...运算符应用范围极小以及babel成本极高,先关闭此特性后续看情况打开
@@ -1,16 +1,14 @@
1
1
  const path = require('path')
2
- const JSON5 = require('json5')
3
2
  const parseRequest = require('./utils/parse-request')
4
3
  const config = require('./config')
5
4
  const createHelpers = require('./helpers')
6
- const getJSONContent = require('./utils/get-json-content')
7
5
  const async = require('async')
8
6
  const { matchCondition } = require('./utils/match-condition')
9
- const { JSON_JS_EXT, MPX_APP_MODULE_ID } = require('./utils/const')
10
- const getRulesRunner = require('./platform')
7
+ const { JSON_JS_EXT } = require('./utils/const')
11
8
  const getEntryName = require('./utils/get-entry-name')
12
9
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
13
10
  const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
11
+ const preProcessJson = require('./utils/pre-process-json')
14
12
 
15
13
  // todo native-loader考虑与mpx-loader或加强复用,原生组件约等于4个区块都为src的.mpx文件
16
14
  module.exports = function (content) {
@@ -25,6 +23,7 @@ module.exports = function (content) {
25
23
  const loaderContext = this
26
24
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
27
25
  const filePath = this.resourcePath
26
+ const moduleId = mpx.getModuleId(filePath)
28
27
  const { resourcePath, queryObj } = parseRequest(this.resource)
29
28
  const packageRoot = queryObj.packageRoot || mpx.currentPackageRoot
30
29
  const mode = mpx.mode
@@ -114,7 +113,29 @@ module.exports = function (content) {
114
113
  new Error('[native-loader][' + this.resource + ']: ' + msg)
115
114
  )
116
115
  }
116
+ let ctorType = pagesMap[resourcePath]
117
+ ? 'page'
118
+ : componentsMap[resourcePath]
119
+ ? 'component'
120
+ : 'app'
121
+ // 处理构造器类型
122
+ const ctor = ctorType === 'page'
123
+ ? (mpx.forceUsePageCtor || mode === 'ali') ? 'Page' : 'Component'
124
+ : ctorType === 'component'
125
+ ? 'Component'
126
+ : 'App'
127
+
128
+ // 支持资源query传入isPage或isComponent支持页面/组件单独编译
129
+ if (ctorType === 'app' && (queryObj.isComponent || queryObj.isPage)) {
130
+ const entryName = getEntryName(this) || mpx.getOutputPath(resourcePath, queryObj.isComponent ? 'component' : 'page')
131
+ ctorType = queryObj.isComponent ? 'component' : 'page'
132
+ this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
133
+ }
117
134
 
135
+ if (ctorType === 'app') {
136
+ const appName = getEntryName(this)
137
+ if (appName) this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
138
+ }
118
139
  // 先读取json获取usingComponents信息
119
140
  async.waterfall([
120
141
  (callback) => {
@@ -141,66 +162,29 @@ module.exports = function (content) {
141
162
  }, callback)
142
163
  },
143
164
  (callback) => {
144
- getJSONContent({
145
- src: typeResourceMap.json,
146
- useJSONJS
147
- }, null, this, callback)
148
- }, (content, callback) => {
149
- let componentPlaceholder = []
150
- let json
151
- try {
152
- json = JSON5.parse(content)
153
- } catch (e) {
154
- return callback(e)
155
- }
156
- let usingComponents = Object.keys(mpx.usingComponents)
157
- const rulesRunnerOptions = {
158
- mode,
165
+ preProcessJson({
166
+ json: {
167
+ src: typeResourceMap.json,
168
+ useJSONJS
169
+ },
159
170
  srcMode,
160
- type: 'json',
161
- waterfall: true,
162
- warn: emitWarning,
163
- error: emitError
164
- }
165
-
166
- let ctorType = pagesMap[resourcePath]
167
- ? 'page'
168
- : componentsMap[resourcePath]
169
- ? 'component'
170
- : 'app'
171
-
172
- // 支持资源query传入isPage或isComponent支持页面/组件单独编译
173
- if (ctorType === 'app' && (queryObj.isComponent || queryObj.isPage)) {
174
- const entryName = getEntryName(this) || mpx.getOutputPath(resourcePath, queryObj.isComponent ? 'component' : 'page')
175
- ctorType = queryObj.isComponent ? 'component' : 'page'
176
- this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
177
- }
178
-
179
- // 处理构造器类型
180
- const ctor = ctorType === 'page'
181
- ? (mpx.forceUsePageCtor || mode === 'ali') ? 'Page' : 'Component'
182
- : ctorType === 'component'
183
- ? 'Component'
184
- : 'App'
185
-
186
- if (ctorType === 'app') {
187
- const appName = getEntryName(this)
188
- if (appName) this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
189
- }
190
-
191
- const moduleId = ctorType === 'app' ? MPX_APP_MODULE_ID : '_' + mpx.pathHash(filePath)
171
+ emitWarning,
172
+ emitError,
173
+ ctorType,
174
+ resourcePath,
175
+ loaderContext
176
+ }, (err, jsonInfo) => {
177
+ if (err) return callback(err)
178
+ callback(null, jsonInfo)
179
+ })
180
+ },
181
+ (jsonInfo, callback) => {
182
+ const {
183
+ componentPlaceholder,
184
+ componentGenerics,
185
+ usingComponentsInfo
186
+ } = jsonInfo
192
187
 
193
- if (ctorType !== 'app') {
194
- rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
195
- }
196
- const rulesRunner = getRulesRunner(rulesRunnerOptions)
197
- if (rulesRunner) rulesRunner(json)
198
- if (json.usingComponents) {
199
- usingComponents = usingComponents.concat(Object.keys(json.usingComponents))
200
- }
201
- if (json.componentPlaceholder) {
202
- componentPlaceholder = componentPlaceholder.concat(Object.values(json.componentPlaceholder))
203
- }
204
188
  const {
205
189
  getRequire
206
190
  } = createHelpers(loaderContext)
@@ -222,8 +206,9 @@ module.exports = function (content) {
222
206
  isNative,
223
207
  ctorType,
224
208
  moduleId,
225
- usingComponents,
226
- componentPlaceholder
209
+ componentGenerics,
210
+ componentPlaceholder,
211
+ usingComponentsInfo: JSON.stringify(usingComponentsInfo)
227
212
  })
228
213
  break
229
214
  case 'styles':
@@ -84,10 +84,9 @@ module.exports = function getSpec ({ warn, error }) {
84
84
  return input
85
85
  }
86
86
 
87
- function fillGlobalComponents (input, { globalComponents }) {
88
- if (globalComponents) {
89
- Object.assign(globalComponents, input.usingComponents)
90
- }
87
+ function fillGlobalComponents (input, { globalComponents }, meta) {
88
+ // 通过meta进行globalComponents的透传
89
+ meta.usingComponents = input.usingComponents
91
90
  return input
92
91
  }
93
92
 
@@ -165,8 +164,6 @@ module.exports = function getSpec ({ warn, error }) {
165
164
  swan: componentNameCapitalToHyphen('usingComponents')
166
165
  },
167
166
  {
168
- // todo ali 2.0已支持全局组件,待移除
169
- ali: addGlobalComponents,
170
167
  swan: addGlobalComponents,
171
168
  qq: addGlobalComponents,
172
169
  tt: addGlobalComponents,
@@ -373,8 +370,6 @@ module.exports = function getSpec ({ warn, error }) {
373
370
  },
374
371
  {
375
372
  test: 'usingComponents',
376
- // todo ali 2.0已支持全局组件,待移除
377
- ali: fillGlobalComponents,
378
373
  qq: fillGlobalComponents,
379
374
  swan: fillGlobalComponents,
380
375
  tt: fillGlobalComponents,
@@ -382,8 +377,6 @@ module.exports = function getSpec ({ warn, error }) {
382
377
  },
383
378
  {
384
379
  test: 'usingComponents',
385
- // todo ali 2.0已支持全局组件,待移除
386
- ali: deletePath({ noLog: true }),
387
380
  qq: deletePath({ noLog: true }),
388
381
  swan: deletePath({ noLog: true }),
389
382
  tt: deletePath({ noLog: true }),
@@ -201,6 +201,11 @@ module.exports = function getSpec ({ warn, error }) {
201
201
  const props = AbbreviationMap[prop]
202
202
  const values = Array.isArray(value) ? value : parseValues(value)
203
203
  const cssMap = []
204
+ // 复合属性不支持单个css var(css var可以接收单个值可以是复合值,复合值运行时不处理,这里前置提示一下)
205
+ if (values.length === 1 && cssVariableExp.test(value)) {
206
+ error(`Property ${prop} in ${selector} is abbreviated property and does not support a single CSS var`)
207
+ return cssMap
208
+ }
204
209
  let idx = 0
205
210
  let propsIdx = 0
206
211
  const diff = values.length - props.length
@@ -296,16 +301,12 @@ module.exports = function getSpec ({ warn, error }) {
296
301
  all: 'background'
297
302
  }
298
303
  const urlExp = /url\(["']?(.*?)["']?\)/
299
- const linerExp = /linear-gradient\(.*\)\s*$/
304
+ const linearExp = /linear-gradient\(.*\)/
300
305
  switch (prop) {
301
306
  case bgPropMap.image: {
302
- // background-image 仅支持背景图
303
- const imgUrl = value.match(urlExp)?.[0]
304
- const linerVal = value.match(linerExp)?.[0]
305
- if (imgUrl) {
306
- return { prop, value: imgUrl }
307
- } else if (linerVal) {
308
- return { prop, value: linerVal }
307
+ // background-image 支持背景图/渐变/css var
308
+ if (cssVariableExp.test(value) || urlExp.test(value) || linearExp.test(value)) {
309
+ return { prop, value }
309
310
  } else {
310
311
  error(`Value of ${prop} in ${selector} selector only support value <url()> or <linear-gradient()>, received ${value}, please check again!`)
311
312
  return false
@@ -344,11 +345,15 @@ module.exports = function getSpec ({ warn, error }) {
344
345
  }
345
346
  case bgPropMap.all: {
346
347
  // background: 仅支持 background-image & background-color & background-repeat
348
+ if (cssVariableExp.test(value)) {
349
+ error(`Property [${bgPropMap.all}] in ${selector} is abbreviated property and does not support CSS var`)
350
+ return false
351
+ }
347
352
  const bgMap = []
348
353
  const values = parseValues(value)
349
354
  values.forEach(item => {
350
355
  const url = item.match(urlExp)?.[0]
351
- const linerVal = item.match(linerExp)?.[0]
356
+ const linerVal = item.match(linearExp)?.[0]
352
357
  if (url) {
353
358
  bgMap.push({ prop: bgPropMap.image, value: url })
354
359
  } else if (linerVal) {
@@ -404,7 +409,7 @@ module.exports = function getSpec ({ warn, error }) {
404
409
  {
405
410
  // 2 个以上的值处理
406
411
  key = key.replace('3d', '')
407
- const vals = val.split(',').splice(0, key === 'rotate' ? 4 : 3)
412
+ const vals = val.split(',', key === 'rotate' ? 4 : 3)
408
413
  // scale(.5) === scaleX(.5) scaleY(.5)
409
414
  if (vals.length === 1 && key === 'scale') {
410
415
  vals.push(vals[0])
@@ -8,6 +8,14 @@ module.exports = function ({ print }) {
8
8
  const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
9
9
  return {
10
10
  test: TAG_NAME,
11
+ android (tag, { el }) {
12
+ el.isBuiltIn = true
13
+ return 'mpx-canvas'
14
+ },
15
+ ios (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'mpx-canvas'
18
+ },
11
19
  props: [
12
20
  {
13
21
  test: /^canvas-id$/,
@@ -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', 'progress', 'rich-text', 'slider', 'audio', 'camera', 'video', 'canvas', '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', 'progress', 'rich-text', 'slider', 'audio', 'camera', 'video', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
15
15
 
16
16
  /**
17
17
  * @param {function(object): function} print
@@ -8,6 +8,7 @@ const RecordLoaderContentDependency = require('../dependencies/RecordLoaderConte
8
8
 
9
9
  module.exports = function ({
10
10
  parts,
11
+ jsonContent,
11
12
  loaderContext,
12
13
  pagesMap,
13
14
  componentsMap,
@@ -19,7 +20,7 @@ module.exports = function ({
19
20
  hasScoped,
20
21
  hasComment,
21
22
  isNative,
22
- usingComponents,
23
+ usingComponentsInfo,
23
24
  componentGenerics,
24
25
  autoScope,
25
26
  callback
@@ -50,7 +51,7 @@ module.exports = function ({
50
51
  srcMode,
51
52
  moduleId,
52
53
  ctorType,
53
- usingComponents,
54
+ usingComponentsInfo,
54
55
  componentGenerics
55
56
  }, callback)
56
57
  },
@@ -63,7 +64,7 @@ module.exports = function ({
63
64
  }, callback)
64
65
  },
65
66
  (callback) => {
66
- processJSON(parts.json, {
67
+ processJSON(jsonContent, {
67
68
  loaderContext,
68
69
  ctorType,
69
70
  pagesMap,