@mpxjs/webpack-plugin 2.8.25-alpha → 2.8.27

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 (43) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +0 -14
  3. package/lib/dependencies/DynamicEntryDependency.js +11 -16
  4. package/lib/dependencies/ResolveDependency.js +0 -4
  5. package/lib/index.js +28 -44
  6. package/lib/json-compiler/index.js +8 -1
  7. package/lib/loader.js +0 -40
  8. package/lib/platform/template/wx/component-config/button.js +2 -14
  9. package/lib/platform/template/wx/component-config/component.js +2 -2
  10. package/lib/platform/template/wx/component-config/image.js +0 -4
  11. package/lib/platform/template/wx/component-config/input.js +0 -4
  12. package/lib/platform/template/wx/component-config/rich-text.js +0 -4
  13. package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
  14. package/lib/platform/template/wx/component-config/switch.js +0 -4
  15. package/lib/platform/template/wx/component-config/text.js +0 -4
  16. package/lib/platform/template/wx/component-config/textarea.js +0 -5
  17. package/lib/platform/template/wx/component-config/view.js +0 -4
  18. package/lib/platform/template/wx/index.js +11 -131
  19. package/lib/resolve-loader.js +1 -4
  20. package/lib/style-compiler/index.js +1 -1
  21. package/lib/template-compiler/compiler.js +74 -60
  22. package/lib/wxss/loader.js +3 -3
  23. package/package.json +3 -6
  24. package/lib/dependencies/AddEntryDependency.js +0 -24
  25. package/lib/runtime/components/tenon/getInnerListeners.js +0 -314
  26. package/lib/runtime/components/tenon/tenon-button.vue +0 -305
  27. package/lib/runtime/components/tenon/tenon-image.vue +0 -61
  28. package/lib/runtime/components/tenon/tenon-input.vue +0 -104
  29. package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
  30. package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
  31. package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
  32. package/lib/runtime/components/tenon/tenon-text-area.vue +0 -77
  33. package/lib/runtime/components/tenon/tenon-text.vue +0 -64
  34. package/lib/runtime/components/tenon/tenon-view.vue +0 -93
  35. package/lib/runtime/optionProcessor.tenon.js +0 -388
  36. package/lib/style-compiler/plugins/hm.js +0 -20
  37. package/lib/tenon/index.js +0 -104
  38. package/lib/tenon/processJSON.js +0 -356
  39. package/lib/tenon/processScript.js +0 -263
  40. package/lib/tenon/processStyles.js +0 -21
  41. package/lib/tenon/processTemplate.js +0 -133
  42. package/lib/utils/fix-swan-relative.js +0 -6
  43. package/lib/utils/get-relative-path.js +0 -25
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
@@ -356,20 +356,6 @@ module.exports = {
356
356
  templatePrefix: 'module.exports = \n'
357
357
  }
358
358
  },
359
- tenon: {
360
- directive: {
361
- if: 'v-if',
362
- elseif: 'v-else-if',
363
- else: 'v-else'
364
- },
365
- wxs: {
366
- tag: 'wxs',
367
- module: 'module',
368
- src: 'src',
369
- ext: '.wxs',
370
- templatePrefix: 'module.exports = \n'
371
- }
372
- },
373
359
  qa: {
374
360
  typeExtMap: {
375
361
  json: '.json',
@@ -28,23 +28,10 @@ class DynamicEntryDependency extends NullDependency {
28
28
  return toPosix([request, entryType, outputPath, packageRoot, relativePath, context, ...range].join('|'))
29
29
  }
30
30
 
31
- collectDynamicRequest (mpx) {
32
- if (!this.packageRoot) return
33
- const curValue = mpx.dynamicEntryInfo[this.packageRoot] = mpx.dynamicEntryInfo[this.packageRoot] || {
34
- hasPage: false,
35
- entries: []
36
- }
37
- if (this.entryType === 'page') {
38
- curValue.hasPage = true
39
- } else {
40
- curValue.entries.push(this.request)
41
- }
42
- }
43
-
44
31
  addEntry (compilation, callback) {
45
32
  const mpx = compilation.__mpx__
46
33
  let { request, entryType, outputPath, relativePath, context, originEntryNode, publicPath, resolver } = this
47
- this.collectDynamicRequest(mpx)
34
+
48
35
  async.waterfall([
49
36
  (callback) => {
50
37
  if (context && resolver) {
@@ -56,12 +43,13 @@ class DynamicEntryDependency extends NullDependency {
56
43
  }
57
44
  },
58
45
  (resource, callback) => {
46
+ const { resourcePath } = parseRequest(resource)
47
+
59
48
  if (!outputPath) {
60
- const { resourcePath } = parseRequest(resource)
61
49
  outputPath = mpx.getOutputPath(resourcePath, entryType)
62
50
  }
63
51
 
64
- const { packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
52
+ const { packageName, packageRoot, outputPath: filename, alreadyOutputted } = mpx.getPackageInfo({
65
53
  resource,
66
54
  outputPath,
67
55
  resourceType: entryType,
@@ -88,6 +76,13 @@ class DynamicEntryDependency extends NullDependency {
88
76
 
89
77
  const key = [resource, filename].join('|')
90
78
 
79
+ mpx.collectDynamicEntryInfo({
80
+ resource,
81
+ packageName,
82
+ filename,
83
+ entryType
84
+ })
85
+
91
86
  if (alreadyOutputted) {
92
87
  const addEntryPromise = mpx.addEntryPromiseMap.get(key)
93
88
  if (addEntryPromise) {
@@ -74,10 +74,6 @@ ResolveDependency.Template = class ResolveDependencyTemplate {
74
74
 
75
75
  getContent (dep) {
76
76
  const { resolved = '' } = dep
77
- // for tenon
78
- if (dep.compilation.__mpx__.mode === 'tenon') {
79
- return `getRelativePath(currentURL, ${JSON.stringify(resolved)}) + '.js'`
80
- }
81
77
  // ?resolve 必定返回绝对路径
82
78
  return JSON.stringify('/' + resolved)
83
79
  }
package/lib/index.js CHANGED
@@ -317,7 +317,7 @@ class MpxWebpackPlugin {
317
317
  let splitChunksPlugin
318
318
  let splitChunksOptions
319
319
 
320
- if (this.options.mode !== 'web' && this.options.mode !== 'tenon') {
320
+ if (this.options.mode !== 'web') {
321
321
  const optimization = compiler.options.optimization
322
322
  optimization.runtimeChunk = {
323
323
  name: (entrypoint) => {
@@ -454,17 +454,17 @@ class MpxWebpackPlugin {
454
454
  stage: -1000
455
455
  }, (compilation, callback) => {
456
456
  processSubpackagesEntriesMap(compilation, () => {
457
- const checkRegisterPack = () => {
458
- for (const packRoot in mpx.dynamicEntryInfo) {
459
- const entryMap = mpx.dynamicEntryInfo[packRoot]
460
- if (!entryMap.hasPage) {
457
+ const checkDynamicEntryInfo = () => {
458
+ for (const packageName in mpx.dynamicEntryInfo) {
459
+ const entryMap = mpx.dynamicEntryInfo[packageName]
460
+ if (packageName !== 'main' && !entryMap.hasPage) {
461
461
  // 引用未注册分包的所有资源
462
- const strRequest = entryMap.entries.join(',')
463
- compilation.errors.push(new Error(`资源${strRequest}目标是打入${packRoot}分包, 但是app.json中并未声明${packRoot}分包`))
462
+ const resources = entryMap.entries.map(info => info.resource).join(',')
463
+ compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`))
464
464
  }
465
465
  }
466
466
  }
467
- checkRegisterPack()
467
+ checkDynamicEntryInfo()
468
468
  callback()
469
469
  })
470
470
  })
@@ -550,7 +550,7 @@ class MpxWebpackPlugin {
550
550
  subpackagesEntriesMap: {},
551
551
  replacePathMap: {},
552
552
  exportModules: new Set(),
553
- // 动态记录注册的分包与注册页面映射
553
+ // 记录动态添加入口的分包信息
554
554
  dynamicEntryInfo: {},
555
555
  // 记录entryModule与entryNode的对应关系,用于体积分析
556
556
  entryNodeModulesMap: new Map(),
@@ -593,13 +593,27 @@ class MpxWebpackPlugin {
593
593
  removedChunks: [],
594
594
  forceProxyEventRules: this.options.forceProxyEventRules,
595
595
  enableAliRequireAsync: this.options.enableAliRequireAsync,
596
+ collectDynamicEntryInfo: ({ resource, packageName, filename, entryType }) => {
597
+ const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
598
+ hasPage: false,
599
+ entries: []
600
+ }
601
+
602
+ if (entryType === 'page') curInfo.hasPage = true
603
+
604
+ curInfo.entries.push({
605
+ entryType,
606
+ resource,
607
+ filename
608
+ })
609
+ },
596
610
  pathHash: (resourcePath) => {
597
611
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
598
612
  return hash(path.relative(this.options.projectRoot, resourcePath))
599
613
  }
600
614
  return hash(resourcePath)
601
615
  },
602
- addEntry (request, name, callback) {
616
+ addEntry: (request, name, callback) => {
603
617
  const dep = EntryPlugin.createDependency(request, { name })
604
618
  compilation.addEntry(compiler.context, dep, { name }, callback)
605
619
  return dep
@@ -1073,27 +1087,7 @@ class MpxWebpackPlugin {
1073
1087
  }
1074
1088
  })
1075
1089
 
1076
- // processing for tenon-store
1077
- if (mpx.mode === 'tenon') {
1078
- let TENON_STORE_ID = 0
1079
- parser.hooks.call.for('imported var').tap('MpxWebpackPlugin', (expr) => {
1080
- if (['createStore', 'createStoreWithThis'].includes(expr.callee.name)) {
1081
- const current = parser.state.current
1082
- const storeOptions = expr.arguments.length && expr.arguments[0]
1083
- if (storeOptions) {
1084
- current.addDependency(new InjectDependency({
1085
- content: 'Object.assign(',
1086
- index: storeOptions.range[0]
1087
- }))
1088
- current.addDependency(new InjectDependency({
1089
- content: `, { __store_id: ${TENON_STORE_ID++} })`,
1090
- index: storeOptions.range[1]
1091
- }))
1092
- }
1093
- }
1094
- })
1095
- }
1096
-
1090
+ // 处理跨平台转换
1097
1091
  if (mpx.srcMode !== mpx.mode) {
1098
1092
  // 处理跨平台全局对象转换
1099
1093
  const transGlobalObject = (expr) => {
@@ -1217,7 +1211,7 @@ class MpxWebpackPlugin {
1217
1211
  name: 'MpxWebpackPlugin',
1218
1212
  stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONS
1219
1213
  }, () => {
1220
- if (mpx.mode === 'web' || mpx.mode === 'tenon') return
1214
+ if (mpx.mode === 'web') return
1221
1215
 
1222
1216
  if (this.options.generateBuildMap) {
1223
1217
  const pagesMap = compilation.__mpx__.pagesMap
@@ -1455,31 +1449,21 @@ try {
1455
1449
  if (mpx.mode === 'web') {
1456
1450
  const mpxStyleOptions = queryObj.mpxStyleOptions
1457
1451
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1458
- const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher') || firstLoader.includes('@hummer/tenon-loader/dist/pitcher.js')
1452
+ const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
1459
1453
  let cssLoaderIndex = -1
1460
1454
  let vueStyleLoaderIndex = -1
1461
1455
  let mpxStyleLoaderIndex = -1
1462
- let tenonStyleLoaderIndex = -1
1463
1456
  loaders.forEach((loader, index) => {
1464
1457
  const currentLoader = toPosix(loader.loader)
1465
1458
  if (currentLoader.includes('css-loader') && cssLoaderIndex === -1) {
1466
1459
  cssLoaderIndex = index
1467
1460
  } else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
1468
1461
  vueStyleLoaderIndex = index
1469
- } else if (currentLoader.includes('@hummer/tenon-style-loader/dist/index.js') && tenonStyleLoaderIndex === -1) {
1470
- tenonStyleLoaderIndex = index
1471
1462
  } else if (currentLoader.includes(styleCompilerPath) && mpxStyleLoaderIndex === -1) {
1472
1463
  mpxStyleLoaderIndex = index
1473
1464
  }
1474
1465
  })
1475
- if (mpx.mode === 'tenon' && mpxStyleLoaderIndex === -1) {
1476
- if (tenonStyleLoaderIndex > -1 && !isPitcherRequest) {
1477
- loaders.splice(tenonStyleLoaderIndex + 1, 0, {
1478
- loader: normalize.lib('style-compiler/index.js'),
1479
- options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {}
1480
- })
1481
- }
1482
- } else if (mpxStyleLoaderIndex === -1) {
1466
+ if (mpxStyleLoaderIndex === -1) {
1483
1467
  let loaderIndex = -1
1484
1468
  if (cssLoaderIndex > -1 && vueStyleLoaderIndex === -1) {
1485
1469
  loaderIndex = cssLoaderIndex
@@ -98,7 +98,14 @@ module.exports = function (content) {
98
98
  if (err) return callback(err)
99
99
  if (!this._compilation) return callback()
100
100
  const targetPath = path.relative(context, file)
101
- this.emitFile(targetPath, content)
101
+ this._compilation.assets[targetPath] = {
102
+ size: function size () {
103
+ return stats.size
104
+ },
105
+ source: function source () {
106
+ return content
107
+ }
108
+ }
102
109
  callback()
103
110
  })
104
111
  }
package/lib/loader.js CHANGED
@@ -11,7 +11,6 @@ const processJSON = require('./web/processJSON')
11
11
  const processScript = require('./web/processScript')
12
12
  const processStyles = require('./web/processStyles')
13
13
  const processTemplate = require('./web/processTemplate')
14
- const processForTenon = require('./tenon/index')
15
14
  const getJSONContent = require('./utils/get-json-content')
16
15
  const normalize = require('./utils/normalize')
17
16
  const getEntryName = require('./utils/get-entry-name')
@@ -128,45 +127,6 @@ module.exports = function (content) {
128
127
  return callback(e)
129
128
  }
130
129
  }
131
-
132
- if (mode === 'tenon') {
133
- if (ctorType === 'app' && !queryObj.app) {
134
- const request = addQuery(this.resource, { app: true })
135
- output += `
136
- import App from ${stringifyRequest(request)}
137
- import * as Tenon from '@hummer/tenon-vue'
138
-
139
- Tenon.render(App)\n`
140
- // 直接结束loader进入parse
141
- this.loaderIndex = -1
142
- return callback(null, output)
143
- }
144
- if (ctorType === 'page' && queryObj.tenon) {
145
- console.log(resourcePath)
146
- const request = addQuery(resourcePath, { page: true })
147
- output += `
148
- import page from ${stringifyRequest(request)}
149
- import * as Tenon from '@hummer/tenon-vue'
150
-
151
- Tenon.render(page)\n`
152
- this.loaderIndex = -1
153
- return callback(null, output)
154
- }
155
- return processForTenon({
156
- mpx,
157
- loaderContext,
158
- isProduction,
159
- queryObj,
160
- filePath,
161
- parts,
162
- ctorType,
163
- autoScope,
164
- componentsMap,
165
- moduleId,
166
- callback
167
- })
168
- }
169
-
170
130
  // 处理mode为web时输出vue格式文件
171
131
  if (mode === 'web') {
172
132
  if (ctorType === 'app' && !queryObj.isApp) {
@@ -28,8 +28,6 @@ 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' })
33
31
  const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
34
32
  const wxPropValueLog = print({ platform: 'wx', tag: TAG_NAME, isError: false, type: 'value' })
35
33
 
@@ -39,10 +37,6 @@ module.exports = function ({ print }) {
39
37
  el.isBuiltIn = true
40
38
  return 'mpx-button'
41
39
  },
42
- tenon (tag, { el }) {
43
- el.isBuiltIn = true
44
- return 'tenon-button'
45
- },
46
40
  props: [
47
41
  {
48
42
  test: 'open-type',
@@ -137,18 +131,13 @@ module.exports = function ({ print }) {
137
131
  },
138
132
  {
139
133
  test: /^(open-type|lang|session-from|send-message-title|send-message-path|send-message-img|show-message-card|app-parameter)$/,
140
- web: webPropLog,
141
- tenon: tenonPropLog
134
+ web: webPropLog
142
135
  },
143
136
  {
144
137
  test: /^(size|type|plain|loading|form-type|hover-class|hover-stop-propagation|hover-start-time|hover-stay-time|use-built-in)$/,
145
138
  web (prop, { el }) {
146
139
  // todo 这部分能力基于内部封装实现
147
140
  el.isBuiltIn = true
148
- },
149
- tenon (prop, { el }) {
150
- // todo 这部分能力基于内部封装实现
151
- el.isBuiltIn = true
152
141
  }
153
142
  },
154
143
  {
@@ -185,8 +174,7 @@ module.exports = function ({ print }) {
185
174
  },
186
175
  {
187
176
  test: /^(getuserinfo|contact|error|launchapp|opensetting|getphonenumber)$/,
188
- web: webEventLog,
189
- tenon: tenonEventLog
177
+ web: webEventLog
190
178
  }
191
179
  ]
192
180
  }
@@ -1,11 +1,11 @@
1
1
  const templateCompiler = require('../../../../template-compiler/compiler')
2
- const parseMustache = templateCompiler.parseMustache
2
+ const parseMustacheWithContext = templateCompiler.parseMustacheWithContext
3
3
  const normalize = require('../../../../utils/normalize')
4
4
  const TAG_NAME = 'component'
5
5
 
6
6
  /** is 属性格式化为中划线(-)连接 */
7
7
  const formatPropIs = (obj, data) => {
8
- const parsed = parseMustache(obj.value)
8
+ const parsed = parseMustacheWithContext(obj.value)
9
9
  let value = parsed.result
10
10
  if (parsed.hasBinding) value = value.slice(1, -1)
11
11
  const el = data.el
@@ -13,10 +13,6 @@ module.exports = function ({ print }) {
13
13
  el.isBuiltIn = true
14
14
  return 'mpx-image'
15
15
  },
16
- tenon (tag, { el }) {
17
- el.isBuiltIn = true
18
- return 'tenon-image'
19
- },
20
16
  props: [
21
17
  {
22
18
  test: /^show-menu-by-longpress$/,
@@ -20,10 +20,6 @@ module.exports = function ({ print }) {
20
20
  el.isBuiltIn = true
21
21
  return 'mpx-input'
22
22
  },
23
- tenon (tag, { el }) {
24
- el.isBuiltIn = true
25
- return 'tenon-input'
26
- },
27
23
  props: [
28
24
  {
29
25
  test: /^(cursor-spacing|auto-focus|adjust-position|hold-keyboard)$/,
@@ -12,10 +12,6 @@ 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
- },
19
15
  props: [
20
16
  {
21
17
  test: /^(space)$/,
@@ -19,10 +19,6 @@ module.exports = function ({ print }) {
19
19
  el.isBuiltIn = true
20
20
  return 'mpx-scroll-view'
21
21
  },
22
- tenon (tag, { el }) {
23
- el.isBuiltIn = true
24
- return 'tenon-scroll-view'
25
- },
26
22
  props: [
27
23
  {
28
24
  test: /^(enable-flex|scroll-anchorin|refresher-enabled|refresher-threshold|refresher-default-style|refresher-background|refresher-triggered|enhanced|bounces|show-scrollbar|paging-enabled|fast-deceleratio)$/,
@@ -10,10 +10,6 @@ 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
- },
17
13
  props: [
18
14
  {
19
15
  test: /^type$/,
@@ -19,10 +19,6 @@ module.exports = function ({ print }) {
19
19
  return 'span'
20
20
  }
21
21
  },
22
- tenon (tag, { el }) {
23
- el.isBuiltIn = true
24
- return 'tenon-text'
25
- },
26
22
  props: [
27
23
  {
28
24
  test: /^(decode|user-select)$/,
@@ -22,11 +22,6 @@ module.exports = function ({ print }) {
22
22
  el.isBuiltIn = true
23
23
  return 'mpx-textarea'
24
24
  },
25
- tenon (tag, { el }) {
26
- // form全量使用内建组件
27
- el.isBuiltIn = true
28
- return 'tenon-textarea'
29
- },
30
25
  props: [
31
26
  {
32
27
  test: /^(auto-focus|fixed|cursor-spacing|cursor|show-confirm-bar|selection-start|selection-end|adjust-position|hold-keyboard|disable-default-padding|confirm-type)$/,
@@ -21,10 +21,6 @@ module.exports = function ({ print }) {
21
21
  return 'div'
22
22
  }
23
23
  },
24
- tenon (tag, { el }) {
25
- el.isBuiltIn = true
26
- return 'tenon-view'
27
- },
28
24
  qa (tag) {
29
25
  return 'div'
30
26
  },