@mpxjs/webpack-plugin 2.9.67 → 2.9.70-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +51 -15
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +53 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  10. package/lib/platform/template/wx/component-config/image.js +4 -0
  11. package/lib/platform/template/wx/component-config/input.js +5 -1
  12. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  13. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  14. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  15. package/lib/platform/template/wx/component-config/switch.js +4 -0
  16. package/lib/platform/template/wx/component-config/text.js +4 -0
  17. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  18. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  19. package/lib/platform/template/wx/component-config/view.js +4 -0
  20. package/lib/platform/template/wx/index.js +127 -1
  21. package/lib/react/processStyles.js +14 -4
  22. package/lib/react/processTemplate.js +3 -0
  23. package/lib/resolve-loader.js +4 -1
  24. package/lib/resolver/AddModePlugin.js +8 -8
  25. package/lib/runtime/components/react/context.ts +6 -0
  26. package/lib/runtime/components/react/dist/context.js +2 -0
  27. package/lib/runtime/components/react/dist/event.config.js +24 -24
  28. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  29. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  30. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  39. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  40. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  41. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  42. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  43. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  44. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  45. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  46. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  47. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  48. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  49. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  50. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  51. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  52. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  53. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  54. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  56. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  57. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  58. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  59. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  60. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  61. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  62. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  63. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  64. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  65. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  66. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  67. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  68. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  69. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  70. package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
  71. package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
  72. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  73. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  74. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  75. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  76. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  77. package/lib/runtime/components/react/dist/utils.jsx +70 -23
  78. package/lib/runtime/components/react/getInnerListeners.ts +36 -43
  79. package/lib/runtime/components/react/mpx-button.tsx +95 -43
  80. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  81. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  82. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  83. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  84. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  85. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  86. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  87. package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
  88. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  89. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  90. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  91. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  92. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  93. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  94. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  95. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  96. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  97. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  98. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  99. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  100. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  101. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  102. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  103. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  104. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  105. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  106. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  107. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  108. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  109. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  110. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  111. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  112. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  113. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  114. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  115. package/lib/runtime/components/react/mpx-view.tsx +81 -59
  116. package/lib/runtime/components/react/mpx-web-view.tsx +46 -19
  117. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  118. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  119. package/lib/runtime/components/react/types/common.ts +2 -0
  120. package/lib/runtime/components/react/types/global.d.ts +3 -16
  121. package/lib/runtime/components/react/utils.tsx +98 -27
  122. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  123. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  124. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  125. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  126. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  127. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  128. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  129. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  130. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  131. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  132. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  133. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  134. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  135. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  136. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  137. package/lib/runtime/optionProcessor.js +7 -16
  138. package/lib/runtime/optionProcessor.tenon.js +84 -0
  139. package/lib/runtime/utils.js +2 -0
  140. package/lib/style-compiler/index.js +1 -1
  141. package/lib/style-compiler/plugins/hm.js +20 -0
  142. package/lib/template-compiler/bind-this.js +7 -2
  143. package/lib/template-compiler/compiler.js +70 -42
  144. package/lib/template-compiler/gen-node-react.js +3 -3
  145. package/lib/tenon/index.js +117 -0
  146. package/lib/tenon/processJSON.js +352 -0
  147. package/lib/tenon/processScript.js +203 -0
  148. package/lib/tenon/processStyles.js +21 -0
  149. package/lib/tenon/processTemplate.js +126 -0
  150. package/lib/tenon/script-helper.js +223 -0
  151. package/lib/utils/env.js +6 -1
  152. package/lib/utils/get-relative-path.js +25 -0
  153. package/package.json +9 -4
  154. package/LICENSE +0 -433
  155. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  156. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  157. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  158. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  159. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  160. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  161. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
package/README.md CHANGED
@@ -13,6 +13,6 @@ module.exports = {
13
13
  new mpxWebpackPlugin({
14
14
  mode: 'wx'
15
15
  })
16
- ],
16
+ ]
17
17
  }
18
18
  ```
package/lib/config.js CHANGED
@@ -368,6 +368,20 @@ module.exports = {
368
368
  templatePrefix: 'module.exports = \n'
369
369
  }
370
370
  },
371
+ tenon: {
372
+ directive: {
373
+ if: 'v-if',
374
+ elseif: 'v-else-if',
375
+ else: 'v-else'
376
+ },
377
+ wxs: {
378
+ tag: 'wxs',
379
+ module: 'module',
380
+ src: 'src',
381
+ ext: '.wxs',
382
+ templatePrefix: 'module.exports = \n'
383
+ }
384
+ },
371
385
  qa: {
372
386
  typeExtMap: {
373
387
  json: '.json',
@@ -0,0 +1,24 @@
1
+ const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
+
3
+ class AddEntryDependency extends NullDependency {
4
+ constructor ({ context, dep, name }) {
5
+ super()
6
+ this.__addEntryParams = [context, dep, name]
7
+ }
8
+
9
+ get type () {
10
+ return 'mpx add entry'
11
+ }
12
+
13
+ // updateHash (hash) {
14
+ // super.updateHash(hash)
15
+ // hash.update(this.childCompileEntryModule.identifier())
16
+ // }
17
+ }
18
+
19
+ AddEntryDependency.Template = class AddEntryDependencyTemplate {
20
+ apply () {
21
+ }
22
+ }
23
+
24
+ module.exports = AddEntryDependency
@@ -76,6 +76,11 @@ ResolveDependency.Template = class ResolveDependencyTemplate {
76
76
 
77
77
  getContent (dep) {
78
78
  const { resolved = '' } = dep
79
+ // for tenon
80
+ if (dep.compilation.__mpx__.mode === 'tenon') {
81
+ // 只支持所有产物在一个目录下的场景 进行相对路径跳转
82
+ return `'./${resolved}.js'`
83
+ }
79
84
  // ?resolve 必定返回绝对路径
80
85
  return JSON.stringify('/' + resolved)
81
86
  }
package/lib/index.js CHANGED
@@ -66,7 +66,7 @@ const emitFile = require('./utils/emit-file')
66
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
- const { isReact, isWeb } = require('./utils/env')
69
+ const { isReact, isWeb, isTenon } = require('./utils/env')
70
70
  const VirtualModulesPlugin = require('webpack-virtual-modules')
71
71
  require('./utils/check-core-version-match')
72
72
 
@@ -323,7 +323,7 @@ class MpxWebpackPlugin {
323
323
  }
324
324
  }
325
325
 
326
- if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
326
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode) && !isTenon(this.options.mode)) {
327
327
  // 强制设置publicPath为'/'
328
328
  if (compiler.options.output.publicPath && compiler.options.output.publicPath !== publicPath) {
329
329
  warnings.push(`webpack options: MpxWebpackPlugin accept options.output.publicPath to be ${publicPath} only, custom options.output.publicPath will be ignored!`)
@@ -348,14 +348,19 @@ class MpxWebpackPlugin {
348
348
  compiler.options.node.global = true
349
349
  }
350
350
 
351
- let addModePlugin
352
- if (['android', 'harmony'].includes(this.options.mode)) {
353
- // 'android' | 'harmony' 下 使用mode = 'ios' 进行兼容兜底
354
- addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file', 'ios')
355
- } else {
356
- addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
351
+ const addModeOptions = {
352
+ fileConditionRules: this.options.fileConditionRules
357
353
  }
358
-
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')
359
364
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
360
365
  const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
361
366
  const dynamicPlugin = new DynamicPlugin('result', this.options.dynamicComponentRules)
@@ -376,7 +381,7 @@ class MpxWebpackPlugin {
376
381
  compiler.options.resolve.plugins.push(dynamicPlugin)
377
382
 
378
383
  const optimization = compiler.options.optimization
379
- if (!isWeb(this.options.mode) && !isReact(this.options.mode)) {
384
+ if (!isWeb(this.options.mode) && !isReact(this.options.mode) && !isTenon(this.options.mode)) {
380
385
  optimization.runtimeChunk = {
381
386
  name: (entrypoint) => {
382
387
  for (const packageName in mpx.independentSubpackagesMap) {
@@ -392,7 +397,7 @@ class MpxWebpackPlugin {
392
397
  let splitChunksOptions = null
393
398
  let splitChunksPlugin = null
394
399
  // 输出web ssr需要将optimization.splitChunks设置为false以关闭splitChunks
395
- if (optimization.splitChunks !== false && !isReact(this.options.mode)) {
400
+ if (optimization.splitChunks !== false && !isReact(this.options.mode) && !isTenon(this.options.mode)) {
396
401
  splitChunksOptions = Object.assign({
397
402
  chunks: 'all',
398
403
  usedExports: optimization.usedExports === true,
@@ -775,7 +780,7 @@ class MpxWebpackPlugin {
775
780
  const hash = mpx.pathHash(resourcePath)
776
781
  const customOutputPath = this.options.customOutputPath
777
782
  if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
778
- if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext).replace(/^\//, '')
783
+ if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext, resourcePath).replace(/^\//, '')
779
784
  if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
780
785
  return path.join(type, name + hash + ext)
781
786
  },
@@ -1477,6 +1482,27 @@ class MpxWebpackPlugin {
1477
1482
  }
1478
1483
  })
1479
1484
 
1485
+ // processing for tenon-store
1486
+ if (mpx.mode === 'tenon') {
1487
+ let TENON_STORE_ID = 0
1488
+ parser.hooks.call.for('imported var').tap('MpxWebpackPlugin', (expr) => {
1489
+ if (['createStore', 'createStoreWithThis'].includes(expr.callee.name)) {
1490
+ const current = parser.state.current
1491
+ const storeOptions = expr.arguments.length && expr.arguments[0]
1492
+ if (storeOptions) {
1493
+ current.addDependency(new InjectDependency({
1494
+ content: 'Object.assign(',
1495
+ index: storeOptions.range[0]
1496
+ }))
1497
+ current.addDependency(new InjectDependency({
1498
+ content: `, { __store_id: ${TENON_STORE_ID++} })`,
1499
+ index: storeOptions.range[1]
1500
+ }))
1501
+ }
1502
+ }
1503
+ })
1504
+ }
1505
+
1480
1506
  parser.hooks.evaluate.for('NewExpression').tap('MpxWebpackPlugin', (expression) => {
1481
1507
  if (/@intlify\/core-base/.test(parser.state.module.resource)) {
1482
1508
  if (expression.callee.name === 'Function') {
@@ -1592,7 +1618,7 @@ class MpxWebpackPlugin {
1592
1618
  name: 'MpxWebpackPlugin',
1593
1619
  stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONS
1594
1620
  }, () => {
1595
- if (isWeb(mpx.mode) || isReact(mpx.mode)) return
1621
+ if (isWeb(mpx.mode) || isReact(mpx.mode) || isTenon(mpx.mode)) return
1596
1622
 
1597
1623
  if (this.options.generateBuildMap) {
1598
1624
  const pagesMap = compilation.__mpx__.pagesMap
@@ -1833,21 +1859,31 @@ try {
1833
1859
  // mpxStyleOptions 为 mpx style 文件的标识,避免 Vue 文件插入 styleCompiler 后导致 vue scoped 样式隔离失效
1834
1860
  if (isWeb(mpx.mode) && queryObj.mpxStyleOptions) {
1835
1861
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1836
- const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
1862
+ const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher') || firstLoader.includes('node_modules/@hummer/tenon-loader/dist/pitcher.js')
1837
1863
  let cssLoaderIndex = -1
1838
1864
  let vueStyleLoaderIndex = -1
1839
1865
  let mpxStyleLoaderIndex = -1
1866
+ let tenonStyleLoaderIndex = -1
1840
1867
  loaders.forEach((loader, index) => {
1841
1868
  const currentLoader = toPosix(loader.loader)
1842
1869
  if (currentLoader.includes('node_modules/css-loader') && cssLoaderIndex === -1) {
1843
1870
  cssLoaderIndex = index
1844
1871
  } else if (currentLoader.includes('node_modules/vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
1845
1872
  vueStyleLoaderIndex = index
1873
+ } else if (currentLoader.includes('@hummer/tenon-style-loader/dist/index.js') && tenonStyleLoaderIndex === -1) {
1874
+ tenonStyleLoaderIndex = index
1846
1875
  } else if (currentLoader.includes(styleCompilerPath) && mpxStyleLoaderIndex === -1) {
1847
1876
  mpxStyleLoaderIndex = index
1848
1877
  }
1849
1878
  })
1850
- if (mpxStyleLoaderIndex === -1) {
1879
+ if (mpx.mode === 'tenon' && mpxStyleLoaderIndex === -1) {
1880
+ if (tenonStyleLoaderIndex > -1 && !isPitcherRequest) {
1881
+ loaders.splice(tenonStyleLoaderIndex + 1, 0, {
1882
+ loader: normalize.lib('style-compiler/index.js'),
1883
+ options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {}
1884
+ })
1885
+ }
1886
+ } else if (mpxStyleLoaderIndex === -1) {
1851
1887
  let loaderIndex = -1
1852
1888
  if (cssLoaderIndex > -1 && vueStyleLoaderIndex === -1) {
1853
1889
  loaderIndex = cssLoaderIndex
@@ -7,7 +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
+ const { isWeb, isReact, isTenon } = require('../utils/env')
11
11
 
12
12
  module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
13
13
  const mpx = loaderContext.getMpx()
@@ -76,7 +76,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
76
76
  const resourceName = path.join(parsed.dir, parsed.name)
77
77
 
78
78
  if (!outputPath) {
79
- if (isScript(ext) && resourceName.includes('node_modules') && !isWeb(mode) && !isReact(mode)) {
79
+ if (isScript(ext) && resourceName.includes('node_modules') && !isWeb(mode) && !isTenon(mode) && !isReact(mode)) {
80
80
  let root = info.descriptionFileRoot
81
81
  let name = 'nativeComponent'
82
82
  if (info.descriptionFileData) {
@@ -139,7 +139,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
139
139
  outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
140
140
  }
141
141
  }
142
- if (isScript(ext) && !isWeb(mode) && !isReact(mode)) {
142
+ if (isScript(ext) && !isWeb(mode) && !isTenon(mode) && !isReact(mode)) {
143
143
  resource = `!!${nativeLoaderPath}!${resource}`
144
144
  }
145
145
  const entry = getDynamicEntry(resource, 'page', outputPath, tarRoot, publicPath + tarRoot)
package/lib/loader.js CHANGED
@@ -4,6 +4,8 @@ const parseRequest = require('./utils/parse-request')
4
4
  const { matchCondition } = require('./utils/match-condition')
5
5
  const addQuery = require('./utils/add-query')
6
6
  const async = require('async')
7
+ const processForTenon = require('./tenon/index')
8
+ const getJSONContent = require('./utils/get-json-content')
7
9
  const normalize = require('./utils/normalize')
8
10
  const getEntryName = require('./utils/get-entry-name')
9
11
  const AppEntryDependency = require('./dependencies/AppEntryDependency')
@@ -17,6 +19,11 @@ const path = require('path')
17
19
  const processWeb = require('./web')
18
20
  const processReact = require('./react')
19
21
  const genMpxCustomElement = require('./runtime-render/gen-mpx-custom-element')
22
+ const loaderUtils = require('loader-utils')
23
+
24
+ function stringifyRequest (loaderContext, request) {
25
+ return loaderUtils.stringifyRequest(loaderContext, request)
26
+ }
20
27
 
21
28
  module.exports = function (content) {
22
29
  this.cacheable()
@@ -128,6 +135,52 @@ module.exports = function (content) {
128
135
  const hasComment = templateAttrs && templateAttrs.comments
129
136
  const isNative = false
130
137
 
138
+
139
+ if (mode === 'tenon') {
140
+ let output = ''
141
+ if (ctorType === 'app' && !queryObj.app) {
142
+ const request = addQuery(this.resource, { app: true })
143
+ output += `
144
+ import App from ${stringifyRequest(loaderContext, request)}
145
+ import * as Tenon from '@hummer/tenon-vue'
146
+
147
+ Tenon.render(App)\n`
148
+ // 直接结束loader进入parse
149
+ this.loaderIndex = -1
150
+ return callback(null, output)
151
+ }
152
+ if (ctorType === 'page' && queryObj.tenon) {
153
+ console.log(resourcePath)
154
+ const request = addQuery(resourcePath, { page: true })
155
+ output += `
156
+ import page from ${stringifyRequest(loaderContext, request)}
157
+ import * as Tenon from '@hummer/tenon-vue'
158
+
159
+ Tenon.render(page)\n`
160
+ this.loaderIndex = -1
161
+ return callback(null, output)
162
+ }
163
+ return processForTenon({
164
+ parts,
165
+ jsonContent,
166
+ loaderContext,
167
+ pagesMap,
168
+ componentsMap,
169
+ queryObj,
170
+ ctorType,
171
+ srcMode,
172
+ moduleId,
173
+ isProduction,
174
+ hasScoped,
175
+ hasComment,
176
+ isNative,
177
+ usingComponentsInfo: JSON.stringify(usingComponentsInfo),
178
+ componentGenerics,
179
+ autoScope,
180
+ callback
181
+ })
182
+ }
183
+
131
184
  // 处理mode为web时输出vue格式文件
132
185
  if (mode === 'web') {
133
186
  return processWeb({
@@ -28,6 +28,8 @@ module.exports = function ({ print }) {
28
28
  const ttEventLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false, type: 'event' })
29
29
  const webPropLog = print({ platform: 'web', tag: TAG_NAME, isError: false })
30
30
  const webEventLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'event' })
31
+ const tenonPropLog = print({ platform: 'tenon', tag: TAG_NAME, isError: false })
32
+ const tenonEventLog = print({ platform: 'tenon', tag: TAG_NAME, isError: false, type: 'event' })
31
33
  const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
32
34
  const wxPropValueLog = print({ platform: 'wx', tag: TAG_NAME, isError: false, type: 'value' })
33
35
  const iosValueLogError = print({ platform: 'ios', tag: TAG_NAME, isError: true, type: 'value' })
@@ -43,6 +45,10 @@ module.exports = function ({ print }) {
43
45
  el.isBuiltIn = true
44
46
  return 'mpx-button'
45
47
  },
48
+ tenon (tag, { el }) {
49
+ el.isBuiltIn = true
50
+ return 'tenon-button'
51
+ },
46
52
  ios (tag, { el }) {
47
53
  el.isBuiltIn = true
48
54
  return 'mpx-button'
@@ -157,13 +163,18 @@ module.exports = function ({ print }) {
157
163
  },
158
164
  {
159
165
  test: /^(open-type|lang|session-from|send-message-title|send-message-path|send-message-img|show-message-card|app-parameter)$/,
160
- web: webPropLog
166
+ web: webPropLog,
167
+ tenon: tenonPropLog
161
168
  },
162
169
  {
163
170
  test: /^(size|type|plain|loading|form-type|hover-class|hover-stop-propagation|hover-start-time|hover-stay-time|use-built-in)$/,
164
171
  web (prop, { el }) {
165
172
  // todo 这部分能力基于内部封装实现
166
173
  el.isBuiltIn = true
174
+ },
175
+ tenon (prop, { el }) {
176
+ // todo 这部分能力基于内部封装实现
177
+ el.isBuiltIn = true
167
178
  }
168
179
  },
169
180
  {
@@ -205,7 +216,8 @@ module.exports = function ({ print }) {
205
216
  },
206
217
  {
207
218
  test: /^(getuserinfo|contact|error|launchapp|opensetting|getphonenumber)$/,
208
- web: webEventLog
219
+ web: webEventLog,
220
+ tenon: tenonEventLog
209
221
  },
210
222
  {
211
223
  test: /^(getuserinfo|contact|getphonenumber|bindgetrealtimephonenumber|error|opensetting|launchapp|chooseavatar|agreeprivacyauthorization)$/,
@@ -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$/,
@@ -15,6 +15,10 @@ module.exports = function ({ print }) {
15
15
  el.isBuiltIn = true
16
16
  return 'mpx-image'
17
17
  },
18
+ tenon (tag, { el }) {
19
+ el.isBuiltIn = true
20
+ return 'tenon-image'
21
+ },
18
22
  ios (tag, { el }) {
19
23
  el.isBuiltIn = true
20
24
  return 'mpx-image'
@@ -26,6 +26,10 @@ module.exports = function ({ print }) {
26
26
  el.isBuiltIn = true
27
27
  return 'mpx-input'
28
28
  },
29
+ tenon (tag, { el }) {
30
+ el.isBuiltIn = true
31
+ return 'tenon-input'
32
+ },
29
33
  ios (tag, { el }) {
30
34
  el.isBuiltIn = true
31
35
  return 'mpx-input'
@@ -92,7 +96,7 @@ module.exports = function ({ print }) {
92
96
  qa: qaPropLog
93
97
  },
94
98
  {
95
- test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|safe-password-.+)$/,
99
+ test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|safe-password-.+)$/,
96
100
  ios: iosPropLog,
97
101
  android: androidPropLog
98
102
  }
@@ -12,6 +12,10 @@ module.exports = function ({ print }) {
12
12
  el.isBuiltIn = true
13
13
  return 'mpx-rich-text'
14
14
  },
15
+ tenon (tag, { el }) {
16
+ el.isBuiltIn = true
17
+ return 'tenon-rich-text'
18
+ },
15
19
  props: [
16
20
  {
17
21
  test: /^(space)$/,
@@ -23,6 +23,10 @@ module.exports = function ({ print }) {
23
23
  el.isBuiltIn = true
24
24
  return 'mpx-scroll-view'
25
25
  },
26
+ tenon (tag, { el }) {
27
+ el.isBuiltIn = true
28
+ return 'tenon-scroll-view'
29
+ },
26
30
  android (tag, { el }) {
27
31
  el.isBuiltIn = true
28
32
  return 'mpx-scroll-view'
@@ -31,7 +31,7 @@ module.exports = function ({ print }) {
31
31
  },
32
32
  props: [
33
33
  {
34
- test: /^(display-multiple-items|skip-hidden-item-layout|easing-function)$/,
34
+ test: /^(display-multiple-items|skip-hidden-item-layout)$/,
35
35
  ali: aliPropLog
36
36
  },
37
37
  {
@@ -10,6 +10,10 @@ module.exports = function ({ print }) {
10
10
  el.isBuiltIn = true
11
11
  return 'mpx-switch'
12
12
  },
13
+ tenon (tag, { el }) {
14
+ el.isBuiltIn = true
15
+ return 'tenon-switch'
16
+ },
13
17
  ios (tag, { el }) {
14
18
  el.isBuiltIn = true
15
19
  return 'mpx-switch'
@@ -22,6 +22,10 @@ module.exports = function ({ print }) {
22
22
  return 'span'
23
23
  }
24
24
  },
25
+ tenon (tag, { el }) {
26
+ el.isBuiltIn = true
27
+ return 'tenon-text'
28
+ },
25
29
  ios (tag, { el }) {
26
30
  el.isBuiltIn = true
27
31
  return 'mpx-text'
@@ -28,6 +28,11 @@ module.exports = function ({ print }) {
28
28
  el.isBuiltIn = true
29
29
  return 'mpx-textarea'
30
30
  },
31
+ tenon (tag, { el }) {
32
+ // form全量使用内建组件
33
+ el.isBuiltIn = true
34
+ return 'tenon-textarea'
35
+ },
31
36
  ios (tag, { el }) {
32
37
  el.isBuiltIn = true
33
38
  return 'mpx-textarea'
@@ -78,7 +83,7 @@ module.exports = function ({ print }) {
78
83
  }
79
84
  },
80
85
  {
81
- test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
86
+ test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
82
87
  ios: iosPropLog,
83
88
  android: androidPropLog
84
89
  }
@@ -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
@@ -23,6 +23,10 @@ module.exports = function ({ print }) {
23
23
  return 'div'
24
24
  }
25
25
  },
26
+ tenon (tag, { el }) {
27
+ el.isBuiltIn = true
28
+ return 'tenon-view'
29
+ },
26
30
  ios (tag, { el }) {
27
31
  el.isBuiltIn = true
28
32
  return 'mpx-view'