@mpxjs/webpack-plugin 2.9.69 → 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.
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/ResolveDependency.js +5 -0
- package/lib/index.js +38 -7
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +53 -0
- package/lib/platform/template/wx/component-config/button.js +14 -2
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +5 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +6 -1
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +127 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolve-loader.js +4 -1
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -165
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +110 -97
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +29 -44
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +20 -24
- package/lib/runtime/components/react/getInnerListeners.ts +35 -28
- package/lib/runtime/components/react/mpx-button.tsx +55 -36
- package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
- package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
- package/lib/runtime/components/react/mpx-form.tsx +10 -8
- package/lib/runtime/components/react/mpx-icon.tsx +10 -15
- package/lib/runtime/components/react/mpx-image.tsx +396 -0
- package/lib/runtime/components/react/mpx-input.tsx +61 -33
- package/lib/runtime/components/react/mpx-label.tsx +14 -13
- package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
- package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
- package/lib/runtime/components/react/mpx-radio.tsx +26 -29
- package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +10 -8
- package/lib/runtime/components/react/mpx-text.tsx +6 -2
- package/lib/runtime/components/react/mpx-view.tsx +37 -45
- package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
- package/lib/runtime/components/react/types/global.d.ts +1 -16
- package/lib/runtime/components/react/utils.tsx +24 -24
- package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
- package/lib/runtime/components/tenon/tenon-button.vue +309 -0
- package/lib/runtime/components/tenon/tenon-image.vue +66 -0
- package/lib/runtime/components/tenon/tenon-input.vue +171 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
- package/lib/runtime/components/tenon/tenon-text.vue +70 -0
- package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +162 -162
- package/lib/runtime/optionProcessor.js +7 -16
- package/lib/runtime/optionProcessor.tenon.js +84 -0
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +67 -40
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/tenon/index.js +117 -0
- package/lib/tenon/processJSON.js +352 -0
- package/lib/tenon/processScript.js +203 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +126 -0
- package/lib/tenon/script-helper.js +223 -0
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-relative-path.js +25 -0
- package/package.json +7 -3
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
buildComponentsMap,
|
|
14
|
+
getRequireScript,
|
|
15
|
+
buildGlobalParams,
|
|
16
|
+
stringifyRequest
|
|
17
|
+
} = require('./script-helper')
|
|
18
|
+
|
|
19
|
+
module.exports = function (script, {
|
|
20
|
+
loaderContext,
|
|
21
|
+
ctorType,
|
|
22
|
+
srcMode,
|
|
23
|
+
moduleId,
|
|
24
|
+
isProduction,
|
|
25
|
+
componentGenerics,
|
|
26
|
+
jsonConfig,
|
|
27
|
+
outputPath,
|
|
28
|
+
builtInComponentsMap,
|
|
29
|
+
genericsInfo,
|
|
30
|
+
wxsModuleMap,
|
|
31
|
+
localComponentsMap,
|
|
32
|
+
localPagesMap
|
|
33
|
+
}, callback) {
|
|
34
|
+
const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// add entry
|
|
38
|
+
// const checkEntryDeps = (callback) => {
|
|
39
|
+
// callback = callback || cacheCallback
|
|
40
|
+
// if (callback && entryDeps.size === 0) {
|
|
41
|
+
// callback()
|
|
42
|
+
// } else {
|
|
43
|
+
// cacheCallback = callback
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
// const addEntryDep = (context, resource, name) => {
|
|
48
|
+
// // 如果loader已经回调,就不再添加entry
|
|
49
|
+
// if (callbacked) return
|
|
50
|
+
// const dep = SingleEntryPlugin.createDependency(resource, name)
|
|
51
|
+
// entryDeps.add(dep)
|
|
52
|
+
// const virtualModule = new AddEntryDependency({
|
|
53
|
+
// context: context._compiler.context,
|
|
54
|
+
// dep,
|
|
55
|
+
// name
|
|
56
|
+
// })
|
|
57
|
+
// /* eslint-disable camelcase */
|
|
58
|
+
// context._module.__has_tenon_entry = true
|
|
59
|
+
// context._module.addDependency(virtualModule)
|
|
60
|
+
// entryDeps.delete(dep)
|
|
61
|
+
// checkEntryDeps()
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
const emitWarning = (msg) => {
|
|
65
|
+
loaderContext.emitWarning(
|
|
66
|
+
new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const emitError = (msg) => {
|
|
71
|
+
loaderContext.emitError(
|
|
72
|
+
new Error('[tenon script processor][' + loaderContext.resource + ']: ' + msg)
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
processPage,
|
|
78
|
+
processDynamicEntry
|
|
79
|
+
} = createJSONHelper({
|
|
80
|
+
loaderContext,
|
|
81
|
+
emitWarning,
|
|
82
|
+
emitError
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// const { getRequire } = createHelpers(loaderContext)
|
|
86
|
+
|
|
87
|
+
// const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
88
|
+
// let tabBarPagesMap = {}
|
|
89
|
+
// if (tabBar && tabBarMap) {
|
|
90
|
+
// // 挂载tabBar组件
|
|
91
|
+
// const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { component: true }))
|
|
92
|
+
// tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
|
|
93
|
+
// // 挂载tabBar页面
|
|
94
|
+
// Object.keys(tabBarMap).forEach((pagePath) => {
|
|
95
|
+
// const pageCfg = localPagesMap[pagePath]
|
|
96
|
+
// if (pageCfg) {
|
|
97
|
+
// const pageRequest = stringifyRequest(pageCfg.resource)
|
|
98
|
+
// if (pageCfg.async) {
|
|
99
|
+
// tabBarPagesMap[pagePath] = `()=>import(${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
|
|
100
|
+
// } else {
|
|
101
|
+
// tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
|
|
102
|
+
// }
|
|
103
|
+
// } else {
|
|
104
|
+
// emitWarning(`TabBar page path ${pagePath} is not exist in local page map, please check!`)
|
|
105
|
+
// }
|
|
106
|
+
// })
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
let output = '/* script */\n'
|
|
110
|
+
|
|
111
|
+
let scriptSrcMode = srcMode
|
|
112
|
+
if (script) {
|
|
113
|
+
scriptSrcMode = script.mode || scriptSrcMode
|
|
114
|
+
} else {
|
|
115
|
+
script = {
|
|
116
|
+
tag: 'script',
|
|
117
|
+
content: ''
|
|
118
|
+
}
|
|
119
|
+
switch (ctorType) {
|
|
120
|
+
case 'app':
|
|
121
|
+
script.content = 'import {createApp} from "@mpxjs/core"\n' +
|
|
122
|
+
'createApp({})\n'
|
|
123
|
+
break
|
|
124
|
+
case 'page':
|
|
125
|
+
script.content = 'import {createPage} from "@mpxjs/core"\n' +
|
|
126
|
+
'createPage({})\n'
|
|
127
|
+
break
|
|
128
|
+
case 'component':
|
|
129
|
+
script.content = 'import {createComponent} from "@mpxjs/core"\n' +
|
|
130
|
+
'createComponent({})\n'
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
output += genComponentTag(script, {
|
|
134
|
+
attrs (script) {
|
|
135
|
+
const attrs = Object.assign({}, script.attrs)
|
|
136
|
+
// src改为内联require,删除
|
|
137
|
+
delete attrs.src
|
|
138
|
+
// script setup通过mpx处理,删除该属性避免vue报错
|
|
139
|
+
delete attrs.setup
|
|
140
|
+
return attrs
|
|
141
|
+
},
|
|
142
|
+
content (script) {
|
|
143
|
+
let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(loaderContext, optionProcessorPath)}\n`
|
|
144
|
+
let hasApp = true
|
|
145
|
+
if (!appInfo.name) {
|
|
146
|
+
hasApp = false
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
// 获取组件集合
|
|
151
|
+
const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })
|
|
152
|
+
|
|
153
|
+
// 获取pageConfig
|
|
154
|
+
const pageConfig = {}
|
|
155
|
+
if (ctorType === 'page') {
|
|
156
|
+
Object.assign(pageConfig, jsonConfig)
|
|
157
|
+
delete pageConfig.usingComponents
|
|
158
|
+
// content += `import * as Tenon from '@hummer/tenon-vue'\n`
|
|
159
|
+
// content += `var page = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { page: true }))}).default\n`
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
|
|
163
|
+
content += getRequireScript({ ctorType, script, loaderContext })
|
|
164
|
+
content += `
|
|
165
|
+
export default processComponentOption({
|
|
166
|
+
option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
|
|
167
|
+
ctorType: ${JSON.stringify(ctorType)},
|
|
168
|
+
outputPath: ${JSON.stringify(outputPath)},
|
|
169
|
+
pageConfig: ${JSON.stringify(pageConfig)},
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
componentsMap: ${shallowStringify(componentsMap)},
|
|
172
|
+
componentGenerics: ${JSON.stringify(componentGenerics)},
|
|
173
|
+
genericsInfo: ${JSON.stringify(genericsInfo)},
|
|
174
|
+
wxsMixin: null,
|
|
175
|
+
hasApp: ${hasApp}
|
|
176
|
+
})\n`
|
|
177
|
+
|
|
178
|
+
content += '\n__dynamic_page_slot__\n'
|
|
179
|
+
|
|
180
|
+
return content
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
output += '\n'
|
|
185
|
+
// 处理pages
|
|
186
|
+
const pageSet = new Set()
|
|
187
|
+
let dynamicPageStr = ''
|
|
188
|
+
async.each(localPagesMap, (pageCfg, callback) => {
|
|
189
|
+
if (typeof pageCfg !== 'string') pageCfg.src = addQuery(pageCfg.src, { tenon: true })
|
|
190
|
+
processPage(pageCfg, loaderContext.context, '', (err, entry, { key } = {}) => {
|
|
191
|
+
if (err) return callback()
|
|
192
|
+
if (pageSet.has(key)) return callback()
|
|
193
|
+
pageSet.add(key)
|
|
194
|
+
dynamicPageStr += `\n"${entry}"`
|
|
195
|
+
callback()
|
|
196
|
+
})
|
|
197
|
+
}, () => {
|
|
198
|
+
output = output.replace('__dynamic_page_slot__', processDynamicEntry(dynamicPageStr) || '')
|
|
199
|
+
callback(null, {
|
|
200
|
+
output
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
}
|
|
@@ -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,126 @@
|
|
|
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
|
+
|
|
8
|
+
module.exports = function (template, {
|
|
9
|
+
loaderContext,
|
|
10
|
+
hasScoped,
|
|
11
|
+
hasComment,
|
|
12
|
+
isNative,
|
|
13
|
+
srcMode,
|
|
14
|
+
moduleId,
|
|
15
|
+
ctorType,
|
|
16
|
+
usingComponentsInfo,
|
|
17
|
+
componentGenerics
|
|
18
|
+
}, callback) {
|
|
19
|
+
const mpx = loaderContext.getMpx()
|
|
20
|
+
const {
|
|
21
|
+
mode,
|
|
22
|
+
env,
|
|
23
|
+
defs,
|
|
24
|
+
wxsContentMap,
|
|
25
|
+
decodeHTMLText,
|
|
26
|
+
externalClasses,
|
|
27
|
+
checkUsingComponents,
|
|
28
|
+
webConfig,
|
|
29
|
+
autoVirtualHostRules
|
|
30
|
+
} = mpx
|
|
31
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
32
|
+
const builtInComponentsMap = {}
|
|
33
|
+
let wxsModuleMap, genericsInfo
|
|
34
|
+
let output = '/* template */\n'
|
|
35
|
+
|
|
36
|
+
if (ctorType === 'app') {
|
|
37
|
+
template = {
|
|
38
|
+
tag: 'template',
|
|
39
|
+
content: '<div class="app">this is app</div>'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (template) {
|
|
44
|
+
// 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
|
|
45
|
+
if (template.src) {
|
|
46
|
+
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
|
|
47
|
+
}
|
|
48
|
+
if (template.lang) {
|
|
49
|
+
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!'))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
output += genComponentTag(template, (template) => {
|
|
53
|
+
if (ctorType === 'app') {
|
|
54
|
+
return template.content
|
|
55
|
+
}
|
|
56
|
+
if (template.content) {
|
|
57
|
+
const templateSrcMode = template.mode || srcMode
|
|
58
|
+
const parsed = templateCompiler.parse(template.content, {
|
|
59
|
+
warn: (msg) => {
|
|
60
|
+
loaderContext.emitWarning(
|
|
61
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
62
|
+
)
|
|
63
|
+
},
|
|
64
|
+
error: (msg) => {
|
|
65
|
+
loaderContext.emitError(
|
|
66
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
67
|
+
)
|
|
68
|
+
},
|
|
69
|
+
usingComponentsInfo,
|
|
70
|
+
hasComment,
|
|
71
|
+
isNative,
|
|
72
|
+
basename: path.basename(resourcePath),
|
|
73
|
+
isComponent: ctorType === 'component',
|
|
74
|
+
mode,
|
|
75
|
+
srcMode: templateSrcMode,
|
|
76
|
+
defs,
|
|
77
|
+
decodeHTMLText,
|
|
78
|
+
// externalClasses: options.externalClasses,
|
|
79
|
+
hasScoped: false,
|
|
80
|
+
moduleId,
|
|
81
|
+
filePath: loaderContext.resourcePath,
|
|
82
|
+
i18n: null,
|
|
83
|
+
checkUsingComponents,
|
|
84
|
+
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
85
|
+
globalComponents: [],
|
|
86
|
+
// web模式下实现抽象组件
|
|
87
|
+
componentGenerics,
|
|
88
|
+
})
|
|
89
|
+
// if (parsed.meta.wxsModuleMap) {
|
|
90
|
+
// wxsModuleMap = parsed.meta.wxsModuleMap
|
|
91
|
+
// }
|
|
92
|
+
// if (parsed.meta.wxsContentMap) {
|
|
93
|
+
// for (let module in parsed.meta.wxsContentMap) {
|
|
94
|
+
// wxsContentMap[`${resourcePath}~${module}`] = parsed.meta.wxsContentMap[module]
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
if (parsed.meta.builtInComponentsMap) {
|
|
98
|
+
Object.keys(parsed.meta.builtInComponentsMap).forEach((name) => {
|
|
99
|
+
builtInComponentsMap[name] = {
|
|
100
|
+
resource: addQuery(parsed.meta.builtInComponentsMap[name], { component: true })
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
// if (parsed.meta.genericsInfo) {
|
|
105
|
+
// genericsInfo = parsed.meta.genericsInfo
|
|
106
|
+
// }
|
|
107
|
+
// 输出H5有多个root element时, 使用div标签包裹
|
|
108
|
+
// if (parsed.root.tag === 'temp-node') {
|
|
109
|
+
// const childLen = calculateRootEleChild(parsed.root.children)
|
|
110
|
+
// if (childLen >= 2) {
|
|
111
|
+
// parsed.root.tag = 'div'
|
|
112
|
+
// }
|
|
113
|
+
// }
|
|
114
|
+
return templateCompiler.serialize(parsed.root)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
output += '\n\n'
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
callback(null, {
|
|
121
|
+
output,
|
|
122
|
+
builtInComponentsMap,
|
|
123
|
+
genericsInfo,
|
|
124
|
+
wxsModuleMap
|
|
125
|
+
})
|
|
126
|
+
}
|
|
@@ -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.
|
|
3
|
+
"version": "2.9.70-alpha.0",
|
|
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": "
|
|
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": "
|
|
105
|
+
"gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
|
|
102
106
|
}
|