@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.1

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 (144) 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 +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +52 -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 +5 -1
  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/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +5 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  25. package/lib/runtime/components/react/dist/locale-provider.jsx +15 -0
  26. package/lib/runtime/components/react/dist/mpx-button.jsx +39 -74
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  28. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  29. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  30. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  31. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +295 -0
  33. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  34. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  35. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  36. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  37. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  38. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  39. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  40. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -14
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +126 -112
  46. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  47. package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +23 -0
  48. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +124 -0
  49. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +40 -0
  50. package/lib/runtime/components/react/dist/mpx-portal.jsx +12 -0
  51. package/lib/runtime/components/react/dist/mpx-provider.jsx +31 -0
  52. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  53. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  54. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  55. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  56. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  57. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +62 -47
  58. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  59. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  60. package/lib/runtime/components/react/dist/mpx-swiper.jsx +613 -0
  61. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  62. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  63. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  64. package/lib/runtime/components/react/dist/mpx-view.jsx +37 -89
  65. package/lib/runtime/components/react/dist/mpx-web-view.jsx +205 -46
  66. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  67. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  68. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  69. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  70. package/lib/runtime/components/react/dist/useAnimationHooks.js +50 -12
  71. package/lib/runtime/components/react/dist/utils.jsx +83 -28
  72. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  73. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  74. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  75. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  76. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  77. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  78. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  79. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  80. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  81. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  82. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  83. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  85. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  87. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  88. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  89. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  90. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  91. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  92. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  93. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  94. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  95. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  96. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  97. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  98. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  99. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  100. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  101. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  102. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  103. package/lib/runtime/components/react/types/global.d.ts +1 -16
  104. package/lib/runtime/components/react/utils.tsx +24 -24
  105. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  106. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  107. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  108. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  109. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  110. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  111. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  112. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  113. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  114. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  115. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  116. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  117. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  118. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  119. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  120. package/lib/runtime/optionProcessor.js +7 -16
  121. package/lib/runtime/optionProcessor.tenon.js +84 -0
  122. package/lib/runtime/utils.js +2 -0
  123. package/lib/style-compiler/index.js +1 -1
  124. package/lib/style-compiler/plugins/hm.js +20 -0
  125. package/lib/template-compiler/bind-this.js +7 -2
  126. package/lib/template-compiler/compiler.js +67 -40
  127. package/lib/template-compiler/gen-node-react.js +2 -2
  128. package/lib/tenon/index.js +112 -0
  129. package/lib/tenon/processJSON.js +352 -0
  130. package/lib/tenon/processScript.js +198 -0
  131. package/lib/tenon/processStyles.js +21 -0
  132. package/lib/tenon/processTemplate.js +125 -0
  133. package/lib/tenon/script-helper.js +223 -0
  134. package/lib/utils/env.js +6 -1
  135. package/lib/utils/get-relative-path.js +25 -0
  136. package/package.json +7 -3
  137. package/LICENSE +0 -433
  138. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  139. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  140. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  141. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  142. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  143. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  144. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
@@ -0,0 +1,198 @@
1
+ const genComponentTag = require('../utils/gen-component-tag')
2
+ const loaderUtils = require('loader-utils')
3
+ const normalize = require('../utils/normalize')
4
+ const shallowStringify = require('../utils/shallow-stringify')
5
+ const optionProcessorPath = normalize.lib('runtime/optionProcessor')
6
+ const async = require('async')
7
+ const createJSONHelper = require('../json-compiler/helper')
8
+ const addQuery = require('../utils/add-query')
9
+
10
+ const {
11
+ buildComponentsMap,
12
+ getRequireScript,
13
+ buildGlobalParams,
14
+ stringifyRequest
15
+ } = require('./script-helper')
16
+
17
+ module.exports = function (script, {
18
+ loaderContext,
19
+ ctorType,
20
+ srcMode,
21
+ moduleId,
22
+ isProduction,
23
+ componentGenerics,
24
+ jsonConfig,
25
+ outputPath,
26
+ builtInComponentsMap,
27
+ genericsInfo,
28
+ wxsModuleMap,
29
+ localComponentsMap,
30
+ localPagesMap
31
+ }, callback) {
32
+ const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()
33
+
34
+ // add entry
35
+ // const checkEntryDeps = (callback) => {
36
+ // callback = callback || cacheCallback
37
+ // if (callback && entryDeps.size === 0) {
38
+ // callback()
39
+ // } else {
40
+ // cacheCallback = callback
41
+ // }
42
+ // }
43
+
44
+ // const addEntryDep = (context, resource, name) => {
45
+ // // 如果loader已经回调,就不再添加entry
46
+ // if (callbacked) return
47
+ // const dep = SingleEntryPlugin.createDependency(resource, name)
48
+ // entryDeps.add(dep)
49
+ // const virtualModule = new AddEntryDependency({
50
+ // context: context._compiler.context,
51
+ // dep,
52
+ // name
53
+ // })
54
+ // /* eslint-disable camelcase */
55
+ // context._module.__has_tenon_entry = true
56
+ // context._module.addDependency(virtualModule)
57
+ // entryDeps.delete(dep)
58
+ // checkEntryDeps()
59
+ // }
60
+
61
+ const emitWarning = (msg) => {
62
+ loaderContext.emitWarning(
63
+ new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
64
+ )
65
+ }
66
+
67
+ const emitError = (msg) => {
68
+ loaderContext.emitError(
69
+ new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
70
+ )
71
+ }
72
+
73
+ const {
74
+ processPage,
75
+ processDynamicEntry
76
+ } = createJSONHelper({
77
+ loaderContext,
78
+ emitWarning,
79
+ emitError
80
+ })
81
+
82
+ // const { getRequire } = createHelpers(loaderContext)
83
+
84
+ // const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
85
+ // let tabBarPagesMap = {}
86
+ // if (tabBar && tabBarMap) {
87
+ // // 挂载tabBar组件
88
+ // const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { component: true }))
89
+ // tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
90
+ // // 挂载tabBar页面
91
+ // Object.keys(tabBarMap).forEach((pagePath) => {
92
+ // const pageCfg = localPagesMap[pagePath]
93
+ // if (pageCfg) {
94
+ // const pageRequest = stringifyRequest(pageCfg.resource)
95
+ // if (pageCfg.async) {
96
+ // tabBarPagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
97
+ // } else {
98
+ // tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
99
+ // }
100
+ // } else {
101
+ // emitWarning(`TabBar page path ${pagePath} is not exist in local page map, please check!`)
102
+ // }
103
+ // })
104
+ // }
105
+
106
+ let output = '/* script */\n'
107
+
108
+ let scriptSrcMode = srcMode
109
+ if (script) {
110
+ scriptSrcMode = script.mode || scriptSrcMode
111
+ } else {
112
+ script = {
113
+ tag: 'script',
114
+ content: ''
115
+ }
116
+ switch (ctorType) {
117
+ case 'app':
118
+ script.content = 'import {createApp} from "@mpxjs/core"\n' +
119
+ 'createApp({})\n'
120
+ break
121
+ case 'page':
122
+ script.content = 'import {createPage} from "@mpxjs/core"\n' +
123
+ 'createPage({})\n'
124
+ break
125
+ case 'component':
126
+ script.content = 'import {createComponent} from "@mpxjs/core"\n' +
127
+ 'createComponent({})\n'
128
+ }
129
+ }
130
+ output += genComponentTag(script, {
131
+ attrs (script) {
132
+ const attrs = Object.assign({}, script.attrs)
133
+ // src改为内联require,删除
134
+ delete attrs.src
135
+ // script setup通过mpx处理,删除该属性避免vue报错
136
+ delete attrs.setup
137
+ return attrs
138
+ },
139
+ content (script) {
140
+ let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
141
+ let hasApp = true
142
+ if (!appInfo.name) {
143
+ hasApp = false
144
+ }
145
+
146
+ // 获取组件集合
147
+ const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })
148
+ // 获取pageConfig
149
+ const pageConfig = {}
150
+ if (ctorType === 'page') {
151
+ Object.assign(pageConfig, jsonConfig)
152
+ delete pageConfig.usingComponents
153
+ // content += `import * as Tenon from '@hummer/tenon-vue'\n`
154
+ // content += `var page = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { page: true }))}).default\n`
155
+ }
156
+
157
+ content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
158
+ content += getRequireScript({ ctorType, script, loaderContext })
159
+ content += `
160
+ export default processComponentOption({
161
+ option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
162
+ ctorType: ${JSON.stringify(ctorType)},
163
+ outputPath: ${JSON.stringify(outputPath)},
164
+ pageConfig: ${JSON.stringify(pageConfig)},
165
+ // @ts-ignore
166
+ componentsMap: ${shallowStringify(componentsMap)},
167
+ componentGenerics: ${JSON.stringify(componentGenerics)},
168
+ genericsInfo: ${JSON.stringify(genericsInfo)},
169
+ wxsMixin: null,
170
+ hasApp: ${hasApp}
171
+ })\n`
172
+
173
+ content += '\n__dynamic_page_slot__\n'
174
+
175
+ return content
176
+ }
177
+ })
178
+
179
+ output += '\n'
180
+ // 处理pages
181
+ const pageSet = new Set()
182
+ let dynamicPageStr = ''
183
+ async.each(localPagesMap, (pageCfg, callback) => {
184
+ if (typeof pageCfg !== 'string') pageCfg.src = addQuery(pageCfg.src, { tenon: true })
185
+ processPage(pageCfg, loaderContext.context, '', (err, entry, { key } = {}) => {
186
+ if (err) return callback()
187
+ if (pageSet.has(key)) return callback()
188
+ pageSet.add(key)
189
+ dynamicPageStr += `\n"${entry}"`
190
+ callback()
191
+ })
192
+ }, () => {
193
+ output = output.replace('__dynamic_page_slot__', processDynamicEntry(dynamicPageStr) || '')
194
+ callback(null, {
195
+ output
196
+ })
197
+ })
198
+ }
@@ -0,0 +1,21 @@
1
+ const genComponentTag = require('../utils/gen-component-tag')
2
+
3
+ module.exports = function (styles, options, callback) {
4
+ let output = '/* styles */\n'
5
+ if (styles.length) {
6
+ styles.forEach((style) => {
7
+ output += genComponentTag(style, {
8
+ attrs (style) {
9
+ const attrs = Object.assign({}, style.attrs)
10
+ if (options.autoScope) attrs.scoped = true
11
+ return attrs
12
+ }
13
+ })
14
+ output += '\n'
15
+ })
16
+ output += '\n'
17
+ }
18
+ callback(null, {
19
+ output
20
+ })
21
+ }
@@ -0,0 +1,125 @@
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
+
7
+ module.exports = function (template, {
8
+ loaderContext,
9
+ hasScoped,
10
+ hasComment,
11
+ isNative,
12
+ srcMode,
13
+ moduleId,
14
+ ctorType,
15
+ usingComponentsInfo,
16
+ componentGenerics
17
+ }, callback) {
18
+ const mpx = loaderContext.getMpx()
19
+ const {
20
+ mode,
21
+ env,
22
+ defs,
23
+ wxsContentMap,
24
+ decodeHTMLText,
25
+ externalClasses,
26
+ checkUsingComponents,
27
+ webConfig,
28
+ autoVirtualHostRules
29
+ } = mpx
30
+ const { resourcePath } = parseRequest(loaderContext.resource)
31
+ const builtInComponentsMap = {}
32
+ let wxsModuleMap, genericsInfo
33
+ let output = '/* template */\n'
34
+
35
+ if (ctorType === 'app') {
36
+ template = {
37
+ tag: 'template',
38
+ content: '<div class="app">this is app</div>'
39
+ }
40
+ }
41
+
42
+ if (template) {
43
+ // 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
44
+ if (template.src) {
45
+ return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
46
+ }
47
+ if (template.lang) {
48
+ 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!'))
49
+ }
50
+
51
+ output += genComponentTag(template, (template) => {
52
+ if (ctorType === 'app') {
53
+ return template.content
54
+ }
55
+ if (template.content) {
56
+ const templateSrcMode = template.mode || srcMode
57
+ const parsed = templateCompiler.parse(template.content, {
58
+ warn: (msg) => {
59
+ loaderContext.emitWarning(
60
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
61
+ )
62
+ },
63
+ error: (msg) => {
64
+ loaderContext.emitError(
65
+ new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
66
+ )
67
+ },
68
+ usingComponentsInfo,
69
+ hasComment,
70
+ isNative,
71
+ basename: path.basename(resourcePath),
72
+ isComponent: ctorType === 'component',
73
+ mode,
74
+ srcMode: templateSrcMode,
75
+ defs,
76
+ decodeHTMLText,
77
+ // externalClasses: options.externalClasses,
78
+ hasScoped: false,
79
+ moduleId,
80
+ filePath: loaderContext.resourcePath,
81
+ i18n: null,
82
+ checkUsingComponents,
83
+ // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
84
+ globalComponents: [],
85
+ // web模式下实现抽象组件
86
+ componentGenerics
87
+ })
88
+ // if (parsed.meta.wxsModuleMap) {
89
+ // wxsModuleMap = parsed.meta.wxsModuleMap
90
+ // }
91
+ // if (parsed.meta.wxsContentMap) {
92
+ // for (let module in parsed.meta.wxsContentMap) {
93
+ // wxsContentMap[`${resourcePath}~${module}`] = parsed.meta.wxsContentMap[module]
94
+ // }
95
+ // }
96
+ if (parsed.meta.builtInComponentsMap) {
97
+ Object.keys(parsed.meta.builtInComponentsMap).forEach((name) => {
98
+ builtInComponentsMap[name] = {
99
+ resource: addQuery(parsed.meta.builtInComponentsMap[name], { component: true })
100
+ }
101
+ })
102
+ }
103
+ // if (parsed.meta.genericsInfo) {
104
+ // genericsInfo = parsed.meta.genericsInfo
105
+ // }
106
+ // 输出H5有多个root element时, 使用div标签包裹
107
+ // if (parsed.root.tag === 'temp-node') {
108
+ // const childLen = calculateRootEleChild(parsed.root.children)
109
+ // if (childLen >= 2) {
110
+ // parsed.root.tag = 'div'
111
+ // }
112
+ // }
113
+ return templateCompiler.serialize(parsed.root)
114
+ }
115
+ })
116
+ output += '\n\n'
117
+ }
118
+
119
+ callback(null, {
120
+ output,
121
+ builtInComponentsMap,
122
+ genericsInfo,
123
+ wxsModuleMap
124
+ })
125
+ }
@@ -0,0 +1,223 @@
1
+ const loaderUtils = require('loader-utils')
2
+ const normalize = require('../utils/normalize')
3
+ const createHelpers = require('../helpers')
4
+ const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
5
+ const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
6
+ const addQuery = require('../utils/add-query')
7
+ const parseRequest = require('../utils/parse-request')
8
+ const shallowStringify = require('../utils/shallow-stringify')
9
+
10
+ function stringifyRequest (loaderContext, request) {
11
+ return loaderUtils.stringifyRequest(loaderContext, request)
12
+ }
13
+
14
+ function getAsyncChunkName (chunkName) {
15
+ if (chunkName && typeof chunkName !== 'boolean') {
16
+ return `/* webpackChunkName: "${chunkName}" */`
17
+ }
18
+ return ''
19
+ }
20
+
21
+ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) {
22
+ const componentsMap = {}
23
+ if (localComponentsMap) {
24
+ Object.keys(localComponentsMap).forEach((componentName) => {
25
+ const componentCfg = localComponentsMap[componentName]
26
+ const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
27
+ if (componentCfg.async) {
28
+ // todo 暂时只处理局部注册的组件作为componentPlaceholder,暂不支持全局组件和原生组件,如使用了支持范围外的组件将不进行placeholder渲染及替换
29
+ if (jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName] && localComponentsMap[jsonConfig.componentPlaceholder[componentName]]) {
30
+ const placeholder = jsonConfig.componentPlaceholder[componentName]
31
+ const placeholderCfg = localComponentsMap[placeholder]
32
+ const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
33
+ if (placeholderCfg.async) {
34
+ loaderContext.emitWarning(
35
+ new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
36
+ )
37
+ }
38
+ componentsMap[componentName] = `function(){return {component: import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)}), loading: getComponent(require(${placeholderRequest}))}}`
39
+ } else {
40
+ componentsMap[componentName] = `function(){return import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)})}`
41
+ }
42
+ } else {
43
+ componentsMap[componentName] = `getComponent(require(${componentRequest}))`
44
+ }
45
+ })
46
+ }
47
+ if (builtInComponentsMap) {
48
+ Object.keys(builtInComponentsMap).forEach((componentName) => {
49
+ const componentCfg = builtInComponentsMap[componentName]
50
+ const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
51
+ componentsMap[componentName] = `getComponent(require(${componentRequest}), {__mpxBuiltIn: true})`
52
+ })
53
+ }
54
+ return componentsMap
55
+ }
56
+
57
+ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBarStr, jsonConfig }) {
58
+ let globalTabBar = ''
59
+ let firstPage = ''
60
+ const pagesMap = {}
61
+ const tabBarPagesMap = {}
62
+ if (tabBar && tabBarMap) {
63
+ // 挂载tabBar组件
64
+ const tabBarRequest = stringifyRequest(loaderContext, addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
65
+ tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
66
+ // 挂载tabBar页面
67
+ Object.keys(tabBarMap).forEach((pagePath) => {
68
+ const pageCfg = localPagesMap[pagePath]
69
+ if (pageCfg) {
70
+ const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
71
+ if (pageCfg.async) {
72
+ tabBarPagesMap[pagePath] = `function(){return import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(function(res) {return getComponent(res, {__mpxPageRoute: ${JSON.stringify(pagePath)}})})}`
73
+ } else {
74
+ tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), {__mpxPageRoute: ${JSON.stringify(pagePath)}})`
75
+ }
76
+ } else {
77
+ loaderContext.emitWarning(
78
+ new Error(`[json processor][${loaderContext.resource}]: TabBar page path ${pagePath} is not exist in local page map, please check!`)
79
+ )
80
+ }
81
+ })
82
+ }
83
+ if (tabBarStr && tabBarPagesMap) {
84
+ globalTabBar += `
85
+ global.__tabBar = ${tabBarStr}
86
+ Vue.observable(global.__tabBar)
87
+ // @ts-ignore
88
+ global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
89
+ }
90
+ Object.keys(localPagesMap).forEach((pagePath) => {
91
+ const pageCfg = localPagesMap[pagePath]
92
+ const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
93
+ if (tabBarMap && tabBarMap[pagePath]) {
94
+ pagesMap[pagePath] = `getComponent(require(${stringifyRequest(loaderContext, tabBarContainerPath)}), {__mpxBuiltIn: true})`
95
+ } else {
96
+ if (pageCfg.async) {
97
+ pagesMap[pagePath] = `function(){return import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(function(res){return getComponent(res, {__mpxPageRoute: ${JSON.stringify(pagePath)}})})}`
98
+ } else {
99
+ // 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
100
+ pagesMap[pagePath] = `getComponent(require(${pageRequest}), {__mpxPageRoute: ${JSON.stringify(pagePath)}})`
101
+ }
102
+ }
103
+
104
+ if (pagePath === jsonConfig.entryPagePath) {
105
+ firstPage = pagePath
106
+ }
107
+ if (!firstPage && pageCfg.isFirst) {
108
+ firstPage = pagePath
109
+ }
110
+ })
111
+ return {
112
+ pagesMap,
113
+ firstPage,
114
+ globalTabBar
115
+ }
116
+ }
117
+
118
+ function getRequireScript ({ script, ctorType, loaderContext }) {
119
+ let content = ' /** script content **/\n'
120
+ const { getRequire } = createHelpers(loaderContext)
121
+ const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
122
+ const extraOptions = {
123
+ ...script.src
124
+ ? { ...queryObj, resourcePath }
125
+ : null,
126
+ ctorType,
127
+ lang: script.lang || 'js'
128
+ }
129
+ content += ` ${getRequire('script', script, extraOptions)}\n`
130
+ return content
131
+ }
132
+
133
+ function buildGlobalParams ({
134
+ moduleId,
135
+ scriptSrcMode,
136
+ loaderContext,
137
+ isProduction,
138
+ jsonConfig,
139
+ webConfig,
140
+ isMain,
141
+ globalTabBar,
142
+ hasApp
143
+ }) {
144
+ let content = ''
145
+ if (isMain) {
146
+ content += `
147
+ global.getApp = function () {}
148
+ global.getCurrentPages = function () {
149
+ if (!(typeof window !== 'undefined')) {
150
+ console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
151
+ }
152
+ var router = global.__mpxRouter
153
+ if (!router) return []
154
+ // @ts-ignore
155
+ return (router.lastStack || router.stack).map(function (item) {
156
+ var page
157
+ var vnode = item.vnode
158
+ if (vnode && vnode.componentInstance) {
159
+ page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
160
+ }
161
+ return page || { route: item.path.slice(1) }
162
+ })
163
+ }
164
+ global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
165
+ global.__mpxGenericsMap = {}
166
+ global.__mpxOptionsMap = {}
167
+ global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
168
+ global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
169
+ global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
170
+ if (globalTabBar) {
171
+ content += globalTabBar
172
+ }
173
+ } else {
174
+ if (!hasApp) {
175
+ content += ' global.__mpxGenericsMap = global.__mpxGenericsMap || {}\n'
176
+ content += ' global.__mpxOptionsMap = global.__mpxOptionsMap || {}\n'
177
+ content += ` global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
178
+ }
179
+ content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
180
+ content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
181
+ content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
182
+ if (!isProduction) {
183
+ content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
184
+ }
185
+ }
186
+ return content
187
+ }
188
+
189
+ function buildI18n ({ i18n, loaderContext }) {
190
+ let i18nContent = ''
191
+ const i18nObj = Object.assign({}, i18n)
192
+ i18nContent += `
193
+ import VueI18n from 'vue-i18n'
194
+ import { createI18n } from 'vue-i18n-bridge'
195
+ Vue.use(VueI18n , { bridge: true })\n`
196
+ const requestObj = {}
197
+ const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
198
+ i18nKeys.forEach((key) => {
199
+ if (i18nObj[`${key}Path`]) {
200
+ requestObj[key] = stringifyRequest(loaderContext, i18nObj[`${key}Path`])
201
+ delete i18nObj[`${key}Path`]
202
+ }
203
+ })
204
+ i18nContent += ` var i18nCfg = ${JSON.stringify(i18nObj)}\n`
205
+ Object.keys(requestObj).forEach((key) => {
206
+ i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
207
+ })
208
+ i18nContent += `
209
+ i18nCfg.legacy = false
210
+ var i18n = createI18n(i18nCfg, VueI18n)
211
+ Vue.use(i18n)
212
+ Mpx.i18n = i18n\n`
213
+ return i18nContent
214
+ }
215
+
216
+ module.exports = {
217
+ buildPagesMap,
218
+ buildComponentsMap,
219
+ getRequireScript,
220
+ buildGlobalParams,
221
+ stringifyRequest,
222
+ buildI18n
223
+ }
package/lib/utils/env.js CHANGED
@@ -6,12 +6,17 @@ function isWeb (mode) {
6
6
  return mode === 'web'
7
7
  }
8
8
 
9
+ function isTenon (mode) {
10
+ return mode === 'tenon'
11
+ }
12
+
9
13
  function isMiniProgram (mode) {
10
- return !isWeb(mode) && !isReact(mode)
14
+ return !isWeb(mode) && !isReact(mode) && !isTenon(mode)
11
15
  }
12
16
 
13
17
  module.exports = {
14
18
  isWeb,
15
19
  isReact,
20
+ isTenon,
16
21
  isMiniProgram
17
22
  }
@@ -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.9.69",
3
+ "version": "2.9.70-alpha.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -27,8 +27,11 @@
27
27
  "@better-scroll/slide": "^2.5.1",
28
28
  "@better-scroll/wheel": "^2.5.1",
29
29
  "@better-scroll/zoom": "^2.5.1",
30
+ "@hummer/tenon-dev-server-webpack-plugin": "0.0.2",
31
+ "@hummer/tenon-loader": "^1.2.0",
32
+ "@hummer/tenon-style-loader": "^0.2.0",
30
33
  "@mpxjs/template-engine": "^2.8.7",
31
- "@mpxjs/utils": "^2.9.69",
34
+ "@mpxjs/utils": ">=2.9.69-alpha",
32
35
  "acorn": "^8.11.3",
33
36
  "acorn-walk": "^7.2.0",
34
37
  "async": "^2.6.0",
@@ -92,11 +95,12 @@
92
95
  "react-native-linear-gradient": "^2.8.3",
93
96
  "react-native-reanimated": "^3.15.2",
94
97
  "react-native-safe-area-context": "^4.12.0",
98
+ "react-native-svg": "^15.8.0",
95
99
  "react-native-webview": "^13.12.2",
96
100
  "rimraf": "^6.0.1"
97
101
  },
98
102
  "engines": {
99
103
  "node": ">=14.14.0"
100
104
  },
101
- "gitHead": "e23c51acc4c2ffdd31fcc6c27aae1aed42d1ade2"
105
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
102
106
  }