@mpxjs/webpack-plugin 2.9.40 → 2.9.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/lib/config.js +63 -97
  2. package/lib/dependencies/DynamicEntryDependency.js +13 -4
  3. package/lib/dependencies/{RecordVueContentDependency.js → RecordLoaderContentDependency.js} +5 -5
  4. package/lib/dependencies/ResolveDependency.js +2 -2
  5. package/lib/helpers.js +5 -1
  6. package/lib/index.js +59 -45
  7. package/lib/json-compiler/helper.js +6 -3
  8. package/lib/json-compiler/index.js +9 -7
  9. package/lib/loader.js +43 -97
  10. package/lib/native-loader.js +0 -1
  11. package/lib/platform/index.js +3 -0
  12. package/lib/platform/style/wx/index.js +414 -0
  13. package/lib/platform/template/wx/component-config/button.js +36 -0
  14. package/lib/platform/template/wx/component-config/image.js +15 -0
  15. package/lib/platform/template/wx/component-config/input.js +41 -0
  16. package/lib/platform/template/wx/component-config/scroll-view.js +27 -1
  17. package/lib/platform/template/wx/component-config/swiper-item.js +13 -1
  18. package/lib/platform/template/wx/component-config/swiper.js +25 -1
  19. package/lib/platform/template/wx/component-config/text.js +15 -0
  20. package/lib/platform/template/wx/component-config/textarea.js +39 -0
  21. package/lib/platform/template/wx/component-config/unsupported.js +18 -0
  22. package/lib/platform/template/wx/component-config/view.js +14 -0
  23. package/lib/platform/template/wx/index.js +88 -4
  24. package/lib/react/index.js +104 -0
  25. package/lib/react/processJSON.js +361 -0
  26. package/lib/react/processMainScript.js +21 -0
  27. package/lib/react/processScript.js +70 -0
  28. package/lib/react/processStyles.js +69 -0
  29. package/lib/react/processTemplate.js +152 -0
  30. package/lib/react/script-helper.js +133 -0
  31. package/lib/react/style-helper.js +91 -0
  32. package/lib/resolver/PackageEntryPlugin.js +1 -0
  33. package/lib/runtime/components/react/event.config.ts +32 -0
  34. package/lib/runtime/components/react/getInnerListeners.ts +289 -0
  35. package/lib/runtime/components/react/getInnerListeners.type.ts +68 -0
  36. package/lib/runtime/components/react/mpx-button.tsx +402 -0
  37. package/lib/runtime/components/react/mpx-image/index.tsx +351 -0
  38. package/lib/runtime/components/react/mpx-image/svg.tsx +21 -0
  39. package/lib/runtime/components/react/mpx-input.tsx +389 -0
  40. package/lib/runtime/components/react/mpx-scroll-view.tsx +412 -0
  41. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +398 -0
  42. package/lib/runtime/components/react/mpx-swiper/index.tsx +68 -0
  43. package/lib/runtime/components/react/mpx-swiper/type.ts +69 -0
  44. package/lib/runtime/components/react/mpx-swiper-item.tsx +42 -0
  45. package/lib/runtime/components/react/mpx-text.tsx +106 -0
  46. package/lib/runtime/components/react/mpx-textarea.tsx +46 -0
  47. package/lib/runtime/components/react/mpx-view.tsx +397 -0
  48. package/lib/runtime/components/react/useNodesRef.ts +39 -0
  49. package/lib/runtime/components/react/utils.ts +92 -0
  50. package/lib/runtime/optionProcessorReact.d.ts +9 -0
  51. package/lib/runtime/optionProcessorReact.js +21 -0
  52. package/lib/runtime/stringify.wxs +10 -28
  53. package/lib/style-compiler/index.js +2 -1
  54. package/lib/template-compiler/compiler.js +280 -37
  55. package/lib/template-compiler/gen-node-react.js +95 -0
  56. package/lib/template-compiler/index.js +15 -24
  57. package/lib/utils/env.js +17 -0
  58. package/lib/utils/make-map.js +1 -1
  59. package/lib/utils/shallow-stringify.js +12 -12
  60. package/lib/web/index.js +123 -0
  61. package/lib/web/processJSON.js +3 -3
  62. package/lib/web/processMainScript.js +25 -23
  63. package/lib/web/processScript.js +12 -16
  64. package/lib/web/processTemplate.js +13 -12
  65. package/lib/web/script-helper.js +14 -22
  66. package/package.json +4 -3
@@ -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])
package/lib/loader.js CHANGED
@@ -5,22 +5,19 @@ const parseRequest = require('./utils/parse-request')
5
5
  const { matchCondition } = require('./utils/match-condition')
6
6
  const addQuery = require('./utils/add-query')
7
7
  const async = require('async')
8
- const processJSON = require('./web/processJSON')
9
- const processScript = require('./web/processScript')
10
- const processStyles = require('./web/processStyles')
11
- const processTemplate = require('./web/processTemplate')
12
8
  const getJSONContent = require('./utils/get-json-content')
13
9
  const normalize = require('./utils/normalize')
14
10
  const getEntryName = require('./utils/get-entry-name')
15
11
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
16
12
  const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
17
- const RecordVueContentDependency = require('./dependencies/RecordVueContentDependency')
18
13
  const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
19
14
  const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
20
15
  const tsWatchRunLoaderFilter = require('./utils/ts-loader-watch-run-loader-filter')
21
16
  const { MPX_APP_MODULE_ID } = require('./utils/const')
17
+ const { isReact } = require('./utils/env')
22
18
  const path = require('path')
23
- const processMainScript = require('./web/processMainScript')
19
+ const processWeb = require('./web')
20
+ const processReact = require('./react')
24
21
  const getRulesRunner = require('./platform')
25
22
  const genMpxCustomElement = require('./runtime-render/gen-mpx-custom-element')
26
23
 
@@ -105,7 +102,6 @@ module.exports = function (content) {
105
102
  getRequire
106
103
  } = createHelpers(loaderContext)
107
104
 
108
- let output = ''
109
105
  const callback = this.async()
110
106
 
111
107
  async.waterfall([
@@ -157,98 +153,47 @@ module.exports = function (content) {
157
153
  }
158
154
  // 处理mode为web时输出vue格式文件
159
155
  if (mode === 'web') {
160
- if (ctorType === 'app' && !queryObj.isApp) {
161
- return async.waterfall([
162
- (callback) => {
163
- processJSON(parts.json, { loaderContext, pagesMap, componentsMap }, callback)
164
- },
165
- (jsonRes, callback) => {
166
- processMainScript(parts.script, {
167
- loaderContext,
168
- ctorType,
169
- srcMode,
170
- moduleId,
171
- isProduction,
172
- jsonConfig: jsonRes.jsonObj,
173
- outputPath: queryObj.outputPath || '',
174
- localComponentsMap: jsonRes.localComponentsMap,
175
- tabBar: jsonRes.jsonObj.tabBar,
176
- tabBarMap: jsonRes.tabBarMap,
177
- tabBarStr: jsonRes.tabBarStr,
178
- localPagesMap: jsonRes.localPagesMap,
179
- resource: this.resource
180
- }, callback)
181
- }
182
- ], (err, scriptRes) => {
183
- if (err) return callback(err)
184
- this.loaderIndex = -1
185
- return callback(null, scriptRes.output)
186
- })
187
- }
188
- // 通过RecordVueContentDependency和vueContentCache确保子request不再重复生成vueContent
189
- const cacheContent = mpx.vueContentCache.get(filePath)
190
- if (cacheContent) return callback(null, cacheContent)
191
-
192
- return async.waterfall([
193
- (callback) => {
194
- async.parallel([
195
- (callback) => {
196
- processTemplate(parts.template, {
197
- loaderContext,
198
- hasScoped,
199
- hasComment,
200
- isNative,
201
- srcMode,
202
- moduleId,
203
- ctorType,
204
- usingComponents,
205
- componentGenerics
206
- }, callback)
207
- },
208
- (callback) => {
209
- processStyles(parts.styles, {
210
- ctorType,
211
- autoScope,
212
- moduleId
213
- }, callback)
214
- },
215
- (callback) => {
216
- processJSON(parts.json, {
217
- loaderContext,
218
- pagesMap,
219
- componentsMap
220
- }, callback)
221
- }
222
- ], (err, res) => {
223
- callback(err, res)
224
- })
225
- },
226
- ([templateRes, stylesRes, jsonRes], callback) => {
227
- output += templateRes.output
228
- output += stylesRes.output
229
- output += jsonRes.output
230
- processScript(parts.script, {
231
- loaderContext,
232
- ctorType,
233
- srcMode,
234
- moduleId,
235
- isProduction,
236
- componentGenerics,
237
- jsonConfig: jsonRes.jsonObj,
238
- outputPath: queryObj.outputPath || '',
239
- builtInComponentsMap: templateRes.builtInComponentsMap,
240
- genericsInfo: templateRes.genericsInfo,
241
- wxsModuleMap: templateRes.wxsModuleMap,
242
- localComponentsMap: jsonRes.localComponentsMap
243
- }, callback)
244
- }
245
- ], (err, scriptRes) => {
246
- if (err) return callback(err)
247
- output += scriptRes.output
248
- this._module.addPresentationalDependency(new RecordVueContentDependency(filePath, output))
249
- callback(null, output)
156
+ return processWeb({
157
+ parts,
158
+ loaderContext,
159
+ pagesMap,
160
+ componentsMap,
161
+ queryObj,
162
+ ctorType,
163
+ srcMode,
164
+ moduleId,
165
+ isProduction,
166
+ hasScoped,
167
+ hasComment,
168
+ isNative,
169
+ usingComponents,
170
+ componentGenerics,
171
+ autoScope,
172
+ callback
250
173
  })
251
174
  }
175
+ // 处理mode为react时输出js格式文件
176
+ if (isReact(mode)) {
177
+ return processReact({
178
+ parts,
179
+ loaderContext,
180
+ pagesMap,
181
+ componentsMap,
182
+ queryObj,
183
+ ctorType,
184
+ srcMode,
185
+ moduleId,
186
+ isProduction,
187
+ hasScoped,
188
+ hasComment,
189
+ isNative,
190
+ usingComponents,
191
+ componentGenerics,
192
+ autoScope,
193
+ callback
194
+ })
195
+ }
196
+
252
197
  const moduleGraph = this._compilation.moduleGraph
253
198
 
254
199
  const issuer = moduleGraph.getIssuer(this._module)
@@ -257,6 +202,7 @@ module.exports = function (content) {
257
202
  return callback(new Error(`Current ${ctorType} [${this.resourcePath}] is issued by [${issuer.resource}], which is not allowed!`))
258
203
  }
259
204
 
205
+ let output = ''
260
206
  // 注入模块id及资源路径
261
207
  output += `global.currentModuleId = ${JSON.stringify(moduleId)}\n`
262
208
  if (!isProduction) {
@@ -225,7 +225,6 @@ module.exports = function (content) {
225
225
  usingComponents,
226
226
  componentPlaceholder
227
227
  })
228
- // if (template.src) extraOptions.resourcePath = resourcePath
229
228
  break
230
229
  case 'styles':
231
230
  if (cssLang) part.lang = cssLang
@@ -16,6 +16,9 @@ module.exports = function getRulesRunner ({
16
16
  template: {
17
17
  wx: require('./template/wx')
18
18
  },
19
+ style: {
20
+ wx: require('./style/wx')
21
+ },
19
22
  json: {
20
23
  wx: require('./json/wx')
21
24
  }