@mpxjs/webpack-plugin 2.8.21 → 2.8.23-alpha

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 (39) 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/DynamicEntryDependency.js +14 -1
  5. package/lib/dependencies/ResolveDependency.js +4 -0
  6. package/lib/index.js +52 -7
  7. package/lib/loader.js +40 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +4 -0
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/switch.js +4 -0
  14. package/lib/platform/template/wx/component-config/text.js +4 -0
  15. package/lib/platform/template/wx/component-config/textarea.js +5 -0
  16. package/lib/platform/template/wx/component-config/view.js +4 -0
  17. package/lib/platform/template/wx/index.js +121 -1
  18. package/lib/resolve-loader.js +4 -1
  19. package/lib/runtime/components/tenon/getInnerListeners.js +314 -0
  20. package/lib/runtime/components/tenon/tenon-button.vue +305 -0
  21. package/lib/runtime/components/tenon/tenon-image.vue +61 -0
  22. package/lib/runtime/components/tenon/tenon-input.vue +104 -0
  23. package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
  24. package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
  25. package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
  26. package/lib/runtime/components/tenon/tenon-text-area.vue +77 -0
  27. package/lib/runtime/components/tenon/tenon-text.vue +64 -0
  28. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  29. package/lib/runtime/optionProcessor.tenon.js +388 -0
  30. package/lib/style-compiler/index.js +1 -1
  31. package/lib/style-compiler/plugins/hm.js +20 -0
  32. package/lib/template-compiler/compiler.js +11 -2
  33. package/lib/tenon/index.js +104 -0
  34. package/lib/tenon/processJSON.js +356 -0
  35. package/lib/tenon/processScript.js +262 -0
  36. package/lib/tenon/processStyles.js +21 -0
  37. package/lib/tenon/processTemplate.js +133 -0
  38. package/lib/utils/get-relative-path.js +25 -0
  39. package/package.json +5 -2
@@ -0,0 +1,133 @@
1
+ const templateCompiler = require('../template-compiler/compiler')
2
+ const genComponentTag = require('../utils/gen-component-tag')
3
+ const addQuery = require('../utils/add-query')
4
+ const path = require('path')
5
+ const parseRequest = require('../utils/parse-request')
6
+ // const getMainCompilation = require('../utils/get-main-compilation')
7
+
8
+ // function calculateRootEleChild (arr) {
9
+ // if (!arr) {
10
+ // return 0
11
+ // }
12
+ // return arr.reduce((total, item) => {
13
+ // if (item.type === 1) {
14
+ // if (item.tag === 'template') {
15
+ // total += calculateRootEleChild(item.children)
16
+ // } else {
17
+ // total += 1
18
+ // }
19
+ // }
20
+ // return total
21
+ // }, 0)
22
+ // }
23
+
24
+ module.exports = function (template, options, callback) {
25
+ const mode = options.mode
26
+ const srcMode = options.srcMode
27
+ const defs = options.defs
28
+ const moduleId = options.moduleId
29
+ const loaderContext = options.loaderContext
30
+ const ctorType = options.ctorType
31
+ const resourcePath = parseRequest(loaderContext.resource).resourcePath
32
+ const builtInComponentsMap = {}
33
+ // const compilation = loaderContext._compilation
34
+ // const mainCompilation = getMainCompilation(compilation)
35
+ // const mpx = mainCompilation.__mpx__
36
+ // const wxsContentMap = mpx.wxsContentMap
37
+ let wxsModuleMap, genericsInfo
38
+ let output = '/* template */\n'
39
+
40
+ if (ctorType === 'app') {
41
+ template = {
42
+ tag: 'template',
43
+ content: '<div class="app">this is app</div>'
44
+ }
45
+ // builtInComponentsMap['mpx-keep-alive'] = {
46
+ // resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { component: true })
47
+ // }
48
+ }
49
+
50
+ if (template) {
51
+ // 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
52
+ if (template.src) {
53
+ return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
54
+ }
55
+ if (template.lang) {
56
+ return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
57
+ }
58
+
59
+ output += genComponentTag(template, (template) => {
60
+ if (ctorType === 'app') {
61
+ return template.content
62
+ }
63
+ if (template.content) {
64
+ const templateSrcMode = template.mode || srcMode
65
+ const parsed = templateCompiler.parse(template.content, {
66
+ warn: (msg) => {
67
+ loaderContext.emitWarning(
68
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
69
+ )
70
+ },
71
+ error: (msg) => {
72
+ loaderContext.emitError(
73
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
74
+ )
75
+ },
76
+ usingComponents: options.usingComponents,
77
+ hasComment: options.hasComment,
78
+ isNative: options.isNative,
79
+ basename: path.basename(resourcePath),
80
+ isComponent: ctorType === 'component',
81
+ mode,
82
+ srcMode: templateSrcMode,
83
+ defs,
84
+ decodeHTMLText: options.decodeHTMLText,
85
+ // externalClasses: options.externalClasses,
86
+ hasScoped: false,
87
+ moduleId,
88
+ filePath: loaderContext.resourcePath,
89
+ i18n: null,
90
+ checkUsingComponents: options.checkUsingComponents,
91
+ // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
92
+ globalComponents: [],
93
+ // web模式下实现抽象组件
94
+ componentGenerics: options.componentGenerics
95
+ })
96
+ // if (parsed.meta.wxsModuleMap) {
97
+ // wxsModuleMap = parsed.meta.wxsModuleMap
98
+ // }
99
+ // if (parsed.meta.wxsContentMap) {
100
+ // for (let module in parsed.meta.wxsContentMap) {
101
+ // wxsContentMap[`${resourcePath}~${module}`] = parsed.meta.wxsContentMap[module]
102
+ // }
103
+ // }
104
+ if (parsed.meta.builtInComponentsMap) {
105
+ Object.keys(parsed.meta.builtInComponentsMap).forEach((name) => {
106
+ builtInComponentsMap[name] = {
107
+ resource: addQuery(parsed.meta.builtInComponentsMap[name], { component: true })
108
+ }
109
+ })
110
+ }
111
+ // if (parsed.meta.genericsInfo) {
112
+ // genericsInfo = parsed.meta.genericsInfo
113
+ // }
114
+ // 输出H5有多个root element时, 使用div标签包裹
115
+ // if (parsed.root.tag === 'temp-node') {
116
+ // const childLen = calculateRootEleChild(parsed.root.children)
117
+ // if (childLen >= 2) {
118
+ // parsed.root.tag = 'div'
119
+ // }
120
+ // }
121
+ return templateCompiler.serialize(parsed.root)
122
+ }
123
+ })
124
+ output += '\n\n'
125
+ }
126
+
127
+ callback(null, {
128
+ output,
129
+ builtInComponentsMap,
130
+ genericsInfo,
131
+ wxsModuleMap
132
+ })
133
+ }
@@ -0,0 +1,25 @@
1
+ function getRelativePath (source, target) {
2
+ // make sure source and target are absolute path
3
+ /^\//.test(source) || (source = '/' + source);
4
+ /^\//.test(target) || (target = '/' + target)
5
+
6
+ source = source && source.replace(/\/[^/]*$/, '') // get dirname
7
+ // check if source or target is root path
8
+ const sourceArr = source.split('/').filter((item, index) => index !== 0 && !!item)
9
+ const targetArr = target.split('/').filter((item, index) => index !== 0 && !!item)
10
+ let i = 0
11
+ while (sourceArr[i] === targetArr[i] && i < sourceArr.length && i < targetArr.length) {
12
+ i++
13
+ }
14
+ let relativePath = ''
15
+ for (let j = 0; j < sourceArr.length - i; j++) {
16
+ relativePath += '../'
17
+ }
18
+ relativePath += targetArr.slice(i).join('/')
19
+ if (relativePath[0] !== '.') relativePath = './' + relativePath
20
+ return relativePath
21
+ }
22
+
23
+ module.exports = {
24
+ getRelativePath
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.21",
3
+ "version": "2.8.23-alpha",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -27,6 +27,9 @@
27
27
  "@better-scroll/slide": "^2.2.1",
28
28
  "@better-scroll/wheel": "^2.2.1",
29
29
  "@better-scroll/zoom": "^2.2.1",
30
+ "@hummer/tenon-dev-server-webpack-plugin": "0.0.2",
31
+ "@hummer/tenon-loader": "^1.1.0",
32
+ "@hummer/tenon-style-loader": "^0.2.0",
30
33
  "acorn-walk": "^7.2.0",
31
34
  "async": "^2.6.0",
32
35
  "consolidate": "^0.15.1",
@@ -82,5 +85,5 @@
82
85
  "engines": {
83
86
  "node": ">=14.14.0"
84
87
  },
85
- "gitHead": "976455b62ed3cd98c7e58d7daca99fd8abb4b5fa"
88
+ "gitHead": "3a6dff432fd46bab36a9866f92cffb6501e69909"
86
89
  }