@mpxjs/webpack-plugin 2.6.115 → 2.7.0-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.
- package/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +58 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +81 -0
- package/lib/dependencies/DynamicEntryDependency.js +171 -0
- package/lib/dependencies/FlagPluginDependency.js +24 -0
- package/lib/dependencies/InjectDependency.js +43 -0
- package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +88 -0
- package/lib/extractor.js +82 -178
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +39 -334
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +889 -525
- package/lib/json-compiler/helper.js +156 -0
- package/lib/json-compiler/index.js +245 -451
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +178 -241
- package/lib/native-loader.js +71 -133
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +2 -3
- 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 +4 -0
- 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/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +149 -3
- package/lib/record-loader.js +11 -0
- package/lib/resolve-loader.js +6 -0
- package/lib/resolver/AddEnvPlugin.js +4 -3
- package/lib/resolver/AddModePlugin.js +4 -3
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +23 -36
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/components/web/getInnerListeners.js +1 -3
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +18 -3
- package/lib/runtime/i18n.wxs +31 -11
- package/lib/runtime/optionProcessor.js +48 -3
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/selector.js +29 -10
- package/lib/style-compiler/index.js +16 -24
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/style-compiler/plugins/rpx.js +43 -37
- package/lib/style-compiler/plugins/scope-id.js +79 -72
- package/lib/style-compiler/plugins/trans-special.js +25 -18
- package/lib/style-compiler/plugins/trim.js +13 -7
- package/lib/style-compiler/plugins/vw.js +22 -16
- package/lib/template-compiler/compiler.js +106 -199
- package/lib/template-compiler/index.js +52 -139
- package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
- package/lib/tenon/index.js +105 -0
- package/lib/tenon/processJSON.js +356 -0
- package/lib/tenon/processScript.js +261 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +10 -0
- package/lib/utils/emit-file.js +10 -0
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +13 -0
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/is-url-request.js +10 -1
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -15
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/resolve.js +13 -0
- package/lib/utils/set.js +47 -0
- package/lib/utils/stringify-loaders-resource.js +25 -0
- package/lib/utils/stringify-query.js +4 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +47 -34
- package/lib/web/processTemplate.js +57 -40
- package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
- package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +4 -8
- package/lib/wxs/WxsTemplatePlugin.js +46 -92
- package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
- package/lib/wxs/loader.js +142 -0
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/lib/wxss/processCss.js +107 -103
- package/package.json +21 -18
- package/lib/built-in-loader.js +0 -49
- package/lib/content-loader.js +0 -13
- package/lib/dependency/ChildCompileDependency.js +0 -24
- package/lib/dependency/InjectDependency.js +0 -26
- package/lib/dependency/RemovedModuleDependency.js +0 -23
- package/lib/dependency/ResolveDependency.js +0 -49
- package/lib/path-loader.js +0 -3
- package/lib/plugin-loader.js +0 -287
- package/lib/staticConfig.js +0 -4
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
- package/lib/utils/try-require.js +0 -16
- package/lib/wxs/wxs-loader.js +0 -117
- package/lib/wxss/getImportPrefix.js +0 -30
|
@@ -41,7 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
data () {
|
|
43
43
|
return {
|
|
44
|
-
currentIndex: this.current
|
|
44
|
+
currentIndex: this.current,
|
|
45
|
+
currentChildLength: 0,
|
|
46
|
+
lastChildLength: 0
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
computed: {
|
|
@@ -81,6 +83,9 @@
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
},
|
|
86
|
+
updated () {
|
|
87
|
+
this.currentChildLength = this.$children && this.$children.length
|
|
88
|
+
},
|
|
84
89
|
watch: {
|
|
85
90
|
current (val) {
|
|
86
91
|
if (this.bs) {
|
|
@@ -89,6 +94,15 @@
|
|
|
89
94
|
}
|
|
90
95
|
this.changeSource = ''
|
|
91
96
|
this.goto(val)
|
|
97
|
+
},
|
|
98
|
+
currentChildLength(val) {
|
|
99
|
+
if (val < this.lastChildLength && val < this.currentIndex) {
|
|
100
|
+
this.goto(0, 0)
|
|
101
|
+
}
|
|
102
|
+
if (this.lastChildLength || (!this.lastChildLength && !this.autoplay)) {
|
|
103
|
+
this.bs && this.bs.refresh()
|
|
104
|
+
}
|
|
105
|
+
this.lastChildLength = val
|
|
92
106
|
}
|
|
93
107
|
},
|
|
94
108
|
activated () {
|
|
@@ -167,10 +181,11 @@
|
|
|
167
181
|
refresh () {
|
|
168
182
|
this.bs && this.bs.refresh()
|
|
169
183
|
},
|
|
170
|
-
goto (index) {
|
|
184
|
+
goto (index, time) {
|
|
171
185
|
const x = this.vertical ? 0 : index
|
|
172
186
|
const y = this.vertical ? index : 0
|
|
173
|
-
|
|
187
|
+
const speed = time === 0 ? 0 : this.duration
|
|
188
|
+
this.bs && this.bs.goToPage(x, y, speed)
|
|
174
189
|
}
|
|
175
190
|
},
|
|
176
191
|
render (createElement) {
|
package/lib/runtime/i18n.wxs
CHANGED
|
@@ -6,7 +6,6 @@ function genRegExp (str, flags) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
function likeArray (arr) {
|
|
11
10
|
if (!__mpx_wxs__) {
|
|
12
11
|
return Array.isArray(arr)
|
|
@@ -23,7 +22,6 @@ function isDef (v) {
|
|
|
23
22
|
return v !== undefined && v !== null
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
25
|
var RE_TOKEN_LIST_VALUE = genRegExp('^[0-9]+')
|
|
28
26
|
var RE_TOKEN_NAMED_VALUE = genRegExp('^[A-Za-z0-9_]+')
|
|
29
27
|
|
|
@@ -40,7 +38,10 @@ function parseMessage (format) {
|
|
|
40
38
|
var char = format[position++]
|
|
41
39
|
if (char === '{') {
|
|
42
40
|
if (text) {
|
|
43
|
-
tokens.push({
|
|
41
|
+
tokens.push({
|
|
42
|
+
type: 'text',
|
|
43
|
+
value: text
|
|
44
|
+
})
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
text = ''
|
|
@@ -56,7 +57,10 @@ function parseMessage (format) {
|
|
|
56
57
|
: isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
|
|
57
58
|
? 'named'
|
|
58
59
|
: 'unknown'
|
|
59
|
-
tokens.push({
|
|
60
|
+
tokens.push({
|
|
61
|
+
value: sub,
|
|
62
|
+
type: type
|
|
63
|
+
})
|
|
60
64
|
} else if (char === '%') {
|
|
61
65
|
// when found rails i18n syntax, skip text capture
|
|
62
66
|
if (format[(position)] !== '{') {
|
|
@@ -67,7 +71,10 @@ function parseMessage (format) {
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
text && tokens.push({
|
|
74
|
+
text && tokens.push({
|
|
75
|
+
type: 'text',
|
|
76
|
+
value: text
|
|
77
|
+
})
|
|
71
78
|
|
|
72
79
|
return tokens
|
|
73
80
|
}
|
|
@@ -263,19 +270,24 @@ function exist (messages, locale, key) {
|
|
|
263
270
|
var messages = {}
|
|
264
271
|
var dateTimeFormats = {}
|
|
265
272
|
var numberFormats = {}
|
|
273
|
+
var locale = 'zh-CN'
|
|
274
|
+
|
|
275
|
+
function getLocale () {
|
|
276
|
+
return __mpx_locale__ || locale
|
|
277
|
+
}
|
|
266
278
|
|
|
267
279
|
function getMessages () {
|
|
268
|
-
// __mpx_messages__会在编译时通过lib/wxs/
|
|
280
|
+
// __mpx_messages__会在编译时通过lib/wxs/i18n-loader注入
|
|
269
281
|
return __mpx_messages__ || messages
|
|
270
282
|
}
|
|
271
283
|
|
|
272
284
|
function getDateTimeFormats () {
|
|
273
|
-
// __mpx_datetime_formats__会在编译时通过lib/wxs/
|
|
285
|
+
// __mpx_datetime_formats__会在编译时通过lib/wxs/i18n-loader注入
|
|
274
286
|
return __mpx_datetime_formats__ || dateTimeFormats
|
|
275
287
|
}
|
|
276
288
|
|
|
277
289
|
function getNumberFormats () {
|
|
278
|
-
// __mpx_number_formats__会在编译时通过lib/wxs/
|
|
290
|
+
// __mpx_number_formats__会在编译时通过lib/wxs/i18n-loader注入
|
|
279
291
|
return __mpx_number_formats__ || numberFormats
|
|
280
292
|
}
|
|
281
293
|
|
|
@@ -339,7 +351,15 @@ module.exports = {
|
|
|
339
351
|
}
|
|
340
352
|
|
|
341
353
|
if (!__mpx_wxs__) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
354
|
+
if (!global.i18n) {
|
|
355
|
+
global.i18n = {
|
|
356
|
+
locale: getLocale(),
|
|
357
|
+
version: 0
|
|
358
|
+
}
|
|
359
|
+
global.i18nMethods = Object.assign(module.exports, {
|
|
360
|
+
__getMessages: getMessages,
|
|
361
|
+
__getDateTimeFormats: getDateTimeFormats,
|
|
362
|
+
__getNumberFormats: getNumberFormats
|
|
363
|
+
})
|
|
364
|
+
}
|
|
345
365
|
}
|
|
@@ -4,7 +4,7 @@ export default function processOption (
|
|
|
4
4
|
option,
|
|
5
5
|
ctorType,
|
|
6
6
|
firstPage,
|
|
7
|
-
|
|
7
|
+
outputPath,
|
|
8
8
|
pageConfig,
|
|
9
9
|
pagesMap,
|
|
10
10
|
componentsMap,
|
|
@@ -85,6 +85,51 @@ export default function processOption (
|
|
|
85
85
|
}
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
+
Vue.filter('transRpxStyle', style => {
|
|
89
|
+
const defaultTransRpxFn = function (match, $1) {
|
|
90
|
+
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
91
|
+
return '' + ($1 * rpx2vwRatio) + 'vw'
|
|
92
|
+
}
|
|
93
|
+
const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
|
|
94
|
+
const parsedStyleObj = {}
|
|
95
|
+
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
96
|
+
const parseStyleText = (cssText) => {
|
|
97
|
+
const listDelimiter = /;(?![^(]*\))/g
|
|
98
|
+
const propertyDelimiter = /:(.+)/
|
|
99
|
+
if (typeof cssText === 'string') {
|
|
100
|
+
cssText.split(listDelimiter).forEach((item) => {
|
|
101
|
+
if (item) {
|
|
102
|
+
var tmp = item.split(propertyDelimiter)
|
|
103
|
+
tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
} else if (typeof cssText === 'object') {
|
|
107
|
+
if (Array.isArray(cssText)) {
|
|
108
|
+
cssText.forEach(cssItem => {
|
|
109
|
+
parseStyleText(cssItem)
|
|
110
|
+
})
|
|
111
|
+
} else {
|
|
112
|
+
Object.assign(parsedStyleObj, cssText)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const transRpxStyleFn = (val) => {
|
|
117
|
+
if (typeof val === 'string' && val.indexOf('rpx') > 0) {
|
|
118
|
+
return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
|
|
119
|
+
}
|
|
120
|
+
return val
|
|
121
|
+
}
|
|
122
|
+
if (style) {
|
|
123
|
+
style.forEach(item => {
|
|
124
|
+
parseStyleText(item)
|
|
125
|
+
for (let key in parsedStyleObj) {
|
|
126
|
+
parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
return parsedStyleObj
|
|
131
|
+
})
|
|
132
|
+
|
|
88
133
|
const routes = []
|
|
89
134
|
|
|
90
135
|
for (const pagePath in pagesMap) {
|
|
@@ -339,8 +384,8 @@ registered in parent context!`)
|
|
|
339
384
|
option.mixins = [mixin]
|
|
340
385
|
}
|
|
341
386
|
|
|
342
|
-
if (
|
|
343
|
-
option.componentPath = '/' +
|
|
387
|
+
if (outputPath) {
|
|
388
|
+
option.componentPath = '/' + outputPath
|
|
344
389
|
}
|
|
345
390
|
|
|
346
391
|
return option
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// import { inBrowser } from '../utils/env'
|
|
2
|
+
|
|
3
|
+
export default function processOption (
|
|
4
|
+
option,
|
|
5
|
+
ctorType,
|
|
6
|
+
firstPage,
|
|
7
|
+
componentId,
|
|
8
|
+
pageConfig,
|
|
9
|
+
pagesMap,
|
|
10
|
+
componentsMap,
|
|
11
|
+
tabBarMap,
|
|
12
|
+
componentGenerics,
|
|
13
|
+
genericsInfo,
|
|
14
|
+
mixin,
|
|
15
|
+
Vue,
|
|
16
|
+
VueRouter,
|
|
17
|
+
i18n
|
|
18
|
+
) {
|
|
19
|
+
if (ctorType === 'app') {
|
|
20
|
+
// 对于app中的组件需要全局注册
|
|
21
|
+
for (const componentName in componentsMap) {
|
|
22
|
+
if (componentsMap.hasOwnProperty(componentName)) {
|
|
23
|
+
const component = componentsMap[componentName]
|
|
24
|
+
Vue.component(componentName, component)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 注册v-ex-classes自定义指令处理externalClasses
|
|
29
|
+
// Vue.directive('ex-classes', (el, binding, vnode) => {
|
|
30
|
+
// const context = vnode.context
|
|
31
|
+
// if (context) {
|
|
32
|
+
// const externalClasses = context.$options.externalClasses || []
|
|
33
|
+
// const classList = el.classList
|
|
34
|
+
// binding.value.forEach((className) => {
|
|
35
|
+
// const actualExternalClassNames = context.$attrs[className]
|
|
36
|
+
// if (externalClasses.indexOf(className) !== -1 && actualExternalClassNames) {
|
|
37
|
+
// classList.remove(className)
|
|
38
|
+
// actualExternalClassNames.split(/\s+/).forEach((actualExternalClassName) => {
|
|
39
|
+
// if (actualExternalClassName) classList.add(actualExternalClassName)
|
|
40
|
+
// })
|
|
41
|
+
// }
|
|
42
|
+
// })
|
|
43
|
+
// }
|
|
44
|
+
// })
|
|
45
|
+
// Vue.directive('animation', (el, binding) => {
|
|
46
|
+
// const newActions = binding?.value?.actions
|
|
47
|
+
// if (el.actions === newActions) {
|
|
48
|
+
// Promise.resolve().then(() => {
|
|
49
|
+
// Object.assign(el.style, el.lastDynamicStyle)
|
|
50
|
+
// })
|
|
51
|
+
// return
|
|
52
|
+
// }
|
|
53
|
+
// el.actions = newActions
|
|
54
|
+
// if (typeof el.setAnimation === 'function') {
|
|
55
|
+
// el.removeEventListener('transitionend', el.setAnimation, false)
|
|
56
|
+
// el.setAnimation = undefined
|
|
57
|
+
// }
|
|
58
|
+
// el.dynamicStyleQueue = []
|
|
59
|
+
// el.lastDynamicStyle = undefined
|
|
60
|
+
// if (Array.isArray(newActions) && newActions.length) {
|
|
61
|
+
// newActions.forEach((item) => {
|
|
62
|
+
// const property = []
|
|
63
|
+
// const { animates, option } = item
|
|
64
|
+
// // 存储动画需要改变的样式属性
|
|
65
|
+
// const dynamicStyle = {
|
|
66
|
+
// transform: ''
|
|
67
|
+
// }
|
|
68
|
+
// animates.forEach((itemAnimation) => {
|
|
69
|
+
// switch (itemAnimation.type) {
|
|
70
|
+
// case 'style':
|
|
71
|
+
// const [key, value] = itemAnimation.args
|
|
72
|
+
// dynamicStyle[key] = value
|
|
73
|
+
// property.push(key)
|
|
74
|
+
// break
|
|
75
|
+
// default:
|
|
76
|
+
// dynamicStyle.transform += `${itemAnimation.type}(${itemAnimation.args}) `
|
|
77
|
+
// if (!property.includes('transform')) {
|
|
78
|
+
// property.push('transform')
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
// })
|
|
82
|
+
// Object.assign(dynamicStyle, {
|
|
83
|
+
// transition: `${parseInt(option.duration)}ms ${option.timingFunction} ${parseInt(option.delay)}ms`,
|
|
84
|
+
// transitionProperty: `${property}`,
|
|
85
|
+
// transformOrigin: option.transformOrigin
|
|
86
|
+
// })
|
|
87
|
+
// el.dynamicStyleQueue.push(dynamicStyle)
|
|
88
|
+
// })
|
|
89
|
+
// el.setAnimation = function () {
|
|
90
|
+
// if (!el.dynamicStyleQueue.length) {
|
|
91
|
+
// el.removeEventListener('transitionend', el.setAnimation, false)
|
|
92
|
+
// return
|
|
93
|
+
// }
|
|
94
|
+
// const dynamicStyle = el.dynamicStyleQueue.shift()
|
|
95
|
+
// Object.assign(el.style, dynamicStyle)
|
|
96
|
+
// el.lastDynamicStyle = dynamicStyle
|
|
97
|
+
// }
|
|
98
|
+
// // 首次动画属性设置
|
|
99
|
+
// setTimeout(el.setAnimation, 0)
|
|
100
|
+
// // 在transitionend事件内设置动画样式
|
|
101
|
+
// el.addEventListener('transitionend', el.setAnimation, false)
|
|
102
|
+
// }
|
|
103
|
+
// })
|
|
104
|
+
|
|
105
|
+
// const routes = []
|
|
106
|
+
|
|
107
|
+
// for (const pagePath in pagesMap) {
|
|
108
|
+
// if (pagesMap.hasOwnProperty(pagePath)) {
|
|
109
|
+
// const page = pagesMap[pagePath]
|
|
110
|
+
// routes.push({
|
|
111
|
+
// path: '/' + pagePath,
|
|
112
|
+
// component: page
|
|
113
|
+
// })
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
// if (routes.length) {
|
|
118
|
+
// if (firstPage) {
|
|
119
|
+
// routes.push({
|
|
120
|
+
// path: '/',
|
|
121
|
+
// redirect: '/' + firstPage
|
|
122
|
+
// })
|
|
123
|
+
// }
|
|
124
|
+
// global.__mpxRouter = option.router = new VueRouter({
|
|
125
|
+
// routes: routes
|
|
126
|
+
// })
|
|
127
|
+
// global.__mpxRouter.stack = []
|
|
128
|
+
// global.__mpxRouter.needCache = null
|
|
129
|
+
// global.__mpxRouter.needRemove = []
|
|
130
|
+
// // 处理reLaunch中传递的url并非首页时的replace逻辑
|
|
131
|
+
// global.__mpxRouter.beforeEach(function (to, from, next) {
|
|
132
|
+
// let action = global.__mpxRouter.__mpxAction
|
|
133
|
+
// const stack = global.__mpxRouter.stack
|
|
134
|
+
|
|
135
|
+
// // 处理人为操作
|
|
136
|
+
// if (!action) {
|
|
137
|
+
// if (stack.length > 1 && stack[stack.length - 2].path === to.path) {
|
|
138
|
+
// action = {
|
|
139
|
+
// type: 'back',
|
|
140
|
+
// delta: 1
|
|
141
|
+
// }
|
|
142
|
+
// } else {
|
|
143
|
+
// action = {
|
|
144
|
+
// type: 'to'
|
|
145
|
+
// }
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
148
|
+
|
|
149
|
+
// const pageInRoutes = routes.some(item => item.path === to.path)
|
|
150
|
+
// if (!pageInRoutes) {
|
|
151
|
+
// if (stack.length < 1) {
|
|
152
|
+
// if (global.__mpxRouter.app.$options.onPageNotFound) {
|
|
153
|
+
// // onPageNotFound,仅首次进入时生效
|
|
154
|
+
// global.__mpxRouter.app.$options.onPageNotFound({
|
|
155
|
+
// path: to.path,
|
|
156
|
+
// query: to.query,
|
|
157
|
+
// isEntryPage: true
|
|
158
|
+
// })
|
|
159
|
+
// return
|
|
160
|
+
// } else {
|
|
161
|
+
// console.warn(`[Mpx runtime warn]: the ${to.path} path does not exist in the application,will redirect to the home page path ${firstPage}`)
|
|
162
|
+
// return next({
|
|
163
|
+
// path: firstPage,
|
|
164
|
+
// replace: true
|
|
165
|
+
// })
|
|
166
|
+
// }
|
|
167
|
+
// } else {
|
|
168
|
+
// let methods = ''
|
|
169
|
+
// switch (action.type) {
|
|
170
|
+
// case 'to':
|
|
171
|
+
// methods = 'navigateTo'
|
|
172
|
+
// break
|
|
173
|
+
// case 'redirect':
|
|
174
|
+
// methods = 'redirectTo'
|
|
175
|
+
// break
|
|
176
|
+
// case 'back':
|
|
177
|
+
// methods = 'navigateBack'
|
|
178
|
+
// break
|
|
179
|
+
// case 'reLaunch':
|
|
180
|
+
// methods = 'reLaunch'
|
|
181
|
+
// break
|
|
182
|
+
// default:
|
|
183
|
+
// methods = 'navigateTo'
|
|
184
|
+
// }
|
|
185
|
+
// throw new Error(`${methods}:fail page "${to.path}" is not found`)
|
|
186
|
+
// }
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
// const insertItem = {
|
|
190
|
+
// path: to.path
|
|
191
|
+
// }
|
|
192
|
+
// // 构建历史栈
|
|
193
|
+
// switch (action.type) {
|
|
194
|
+
// case 'to':
|
|
195
|
+
// stack.push(insertItem)
|
|
196
|
+
// global.__mpxRouter.needCache = insertItem
|
|
197
|
+
// break
|
|
198
|
+
// case 'back':
|
|
199
|
+
// global.__mpxRouter.needRemove = stack.splice(stack.length - action.delta, action.delta)
|
|
200
|
+
// break
|
|
201
|
+
// case 'redirect':
|
|
202
|
+
// global.__mpxRouter.needRemove = stack.splice(stack.length - 1, 1, insertItem)
|
|
203
|
+
// global.__mpxRouter.needCache = insertItem
|
|
204
|
+
// break
|
|
205
|
+
// case 'switch':
|
|
206
|
+
// if (!action.replaced) {
|
|
207
|
+
// action.replaced = true
|
|
208
|
+
// return next({
|
|
209
|
+
// path: action.path,
|
|
210
|
+
// replace: true
|
|
211
|
+
// })
|
|
212
|
+
// } else {
|
|
213
|
+
// // 将非tabBar页面remove
|
|
214
|
+
// let tabItem = null
|
|
215
|
+
// global.__mpxRouter.needRemove = stack.filter((item) => {
|
|
216
|
+
// if (tabBarMap[item.path.slice(1)]) {
|
|
217
|
+
// tabItem = item
|
|
218
|
+
// return false
|
|
219
|
+
// }
|
|
220
|
+
// return true
|
|
221
|
+
// })
|
|
222
|
+
// if (tabItem) {
|
|
223
|
+
// global.__mpxRouter.stack = [tabItem]
|
|
224
|
+
// } else {
|
|
225
|
+
// global.__mpxRouter.stack = [insertItem]
|
|
226
|
+
// global.__mpxRouter.needCache = insertItem
|
|
227
|
+
// }
|
|
228
|
+
// }
|
|
229
|
+
// break
|
|
230
|
+
// case 'reLaunch':
|
|
231
|
+
// if (!action.replaced) {
|
|
232
|
+
// action.replaced = true
|
|
233
|
+
// return next({
|
|
234
|
+
// path: action.path,
|
|
235
|
+
// query: {
|
|
236
|
+
// reLaunchCount: action.reLaunchCount
|
|
237
|
+
// },
|
|
238
|
+
// replace: true
|
|
239
|
+
// })
|
|
240
|
+
// } else {
|
|
241
|
+
// global.__mpxRouter.needRemove = stack
|
|
242
|
+
// global.__mpxRouter.stack = [insertItem]
|
|
243
|
+
// global.__mpxRouter.needCache = insertItem
|
|
244
|
+
// }
|
|
245
|
+
// }
|
|
246
|
+
// next()
|
|
247
|
+
// })
|
|
248
|
+
// // 处理visibilitychange时触发当前活跃页面组件的onshow/onhide
|
|
249
|
+
// if (inBrowser) {
|
|
250
|
+
// // const errorHandler = function (e) {
|
|
251
|
+
// // if (global.__mpxAppCbs && global.__mpxAppCbs.error) {
|
|
252
|
+
// // global.__mpxAppCbs.error.forEach((cb) => {
|
|
253
|
+
// // cb(e)
|
|
254
|
+
// // })
|
|
255
|
+
// // }
|
|
256
|
+
// // }
|
|
257
|
+
// // Vue.config.errorHandler = errorHandler
|
|
258
|
+
// // window.addEventListener('error', errorHandler)
|
|
259
|
+
// // window.addEventListener('unhandledrejection', event => {
|
|
260
|
+
// // errorHandler(event.reason)
|
|
261
|
+
// // })
|
|
262
|
+
// // document.addEventListener('visibilitychange', function () {
|
|
263
|
+
// // const vnode = global.__mpxRouter && global.__mpxRouter.__mpxActiveVnode
|
|
264
|
+
// // if (vnode && vnode.componentInstance) {
|
|
265
|
+
// // const currentPage = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
|
|
266
|
+
// // if (document.hidden) {
|
|
267
|
+
// // if (global.__mpxAppCbs && global.__mpxAppCbs.hide) {
|
|
268
|
+
// // global.__mpxAppCbs.hide.forEach((cb) => {
|
|
269
|
+
// // cb()
|
|
270
|
+
// // })
|
|
271
|
+
// // }
|
|
272
|
+
// // if (currentPage) {
|
|
273
|
+
// // currentPage.mpxPageStatus = 'hide'
|
|
274
|
+
// // currentPage.onHide && currentPage.onHide()
|
|
275
|
+
// // }
|
|
276
|
+
// // } else {
|
|
277
|
+
// // if (global.__mpxAppCbs && global.__mpxAppCbs.show) {
|
|
278
|
+
// // global.__mpxAppCbs.show.forEach((cb) => {
|
|
279
|
+
// // // todo 实现app.onShow参数
|
|
280
|
+
// // /* eslint-disable standard/no-callback-literal */
|
|
281
|
+
// // cb({})
|
|
282
|
+
// // })
|
|
283
|
+
// // }
|
|
284
|
+
// // if (currentPage) {
|
|
285
|
+
// // currentPage.mpxPageStatus = 'show'
|
|
286
|
+
// // currentPage.onShow && currentPage.onShow()
|
|
287
|
+
// // }
|
|
288
|
+
// // }
|
|
289
|
+
// // }
|
|
290
|
+
// // })
|
|
291
|
+
// // 初始化length
|
|
292
|
+
// // global.__mpxRouter.__mpxHistoryLength = global.history.length
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
295
|
+
|
|
296
|
+
// if (i18n) {
|
|
297
|
+
// option.i18n = i18n
|
|
298
|
+
// }
|
|
299
|
+
} else {
|
|
300
|
+
// 局部注册页面和组件中依赖的组件
|
|
301
|
+
for (const componentName in componentsMap) {
|
|
302
|
+
if (componentsMap.hasOwnProperty(componentName)) {
|
|
303
|
+
const component = componentsMap[componentName]
|
|
304
|
+
if (!option.components) {
|
|
305
|
+
option.components = {}
|
|
306
|
+
}
|
|
307
|
+
option.components[componentName] = component
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// if (genericsInfo) {
|
|
312
|
+
// const genericHash = genericsInfo.hash
|
|
313
|
+
// global.__mpxGenericsMap[genericHash] = {}
|
|
314
|
+
// Object.keys(genericsInfo.map).forEach((genericValue) => {
|
|
315
|
+
// if (componentsMap[genericValue]) {
|
|
316
|
+
// global.__mpxGenericsMap[genericHash][genericValue] = componentsMap[genericValue]
|
|
317
|
+
// } else {
|
|
318
|
+
// console.log(option)
|
|
319
|
+
// console.warn(`[Mpx runtime warn]: generic value "${genericValue}" must be
|
|
320
|
+
// registered in parent context!`)
|
|
321
|
+
// }
|
|
322
|
+
// })
|
|
323
|
+
// }
|
|
324
|
+
|
|
325
|
+
// if (componentGenerics) {
|
|
326
|
+
// option.props = option.props || {}
|
|
327
|
+
// option.props.generichash = String
|
|
328
|
+
// Object.keys(componentGenerics).forEach((genericName) => {
|
|
329
|
+
// if (componentGenerics[genericName].default) {
|
|
330
|
+
// option.props[`generic${genericName}`] = {
|
|
331
|
+
// type: String,
|
|
332
|
+
// default: `${genericName}default`
|
|
333
|
+
// }
|
|
334
|
+
// } else {
|
|
335
|
+
// option.props[`generic${genericName}`] = String
|
|
336
|
+
// }
|
|
337
|
+
// })
|
|
338
|
+
// }
|
|
339
|
+
|
|
340
|
+
if (ctorType === 'page') {
|
|
341
|
+
(option.mixins ? option.mixins : (option.mixins = [])).push({
|
|
342
|
+
// cache page instance in tenon
|
|
343
|
+
created () {
|
|
344
|
+
global.__currentPageInstance = this
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (mixin) {
|
|
352
|
+
if (option.mixins) {
|
|
353
|
+
option.mixins.push(mixin)
|
|
354
|
+
} else {
|
|
355
|
+
option.mixins = [mixin]
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (componentId) {
|
|
360
|
+
option.componentPath = '/' + componentId
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return option
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function getComponent (component, extendOptions) {
|
|
367
|
+
component = component.__esModule ? component.default : component
|
|
368
|
+
// eslint-disable-next-line
|
|
369
|
+
if (extendOptions) Object.assign(component, extendOptions)
|
|
370
|
+
return component
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function getWxsMixin (wxsModules) {
|
|
374
|
+
if (!wxsModules) return {}
|
|
375
|
+
return {
|
|
376
|
+
created () {
|
|
377
|
+
Object.keys(wxsModules).forEach((key) => {
|
|
378
|
+
if (key in this) {
|
|
379
|
+
console.error(`[Mpx runtime error]: The wxs module key [${key}] exist in the component/page instance already, please check and rename it!`)
|
|
380
|
+
} else {
|
|
381
|
+
this[key] = wxsModules[key]
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
package/lib/selector.js
CHANGED
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
const parseComponent = require('./parser')
|
|
2
|
-
const
|
|
3
|
-
const getMainCompilation = require('./utils/get-main-compilation')
|
|
2
|
+
const parseRequest = require('./utils/parse-request')
|
|
4
3
|
|
|
5
4
|
module.exports = function (content) {
|
|
6
5
|
this.cacheable()
|
|
7
|
-
|
|
8
|
-
const mpx =
|
|
6
|
+
// todo 移除mpx访问依赖,支持thread-loader
|
|
7
|
+
const mpx = this.getMpx()
|
|
9
8
|
if (!mpx) {
|
|
10
9
|
return content
|
|
11
10
|
}
|
|
11
|
+
const { queryObj } = parseRequest(this.resource)
|
|
12
|
+
const ctorType = queryObj.ctorType
|
|
13
|
+
const type = queryObj.type
|
|
14
|
+
const index = queryObj.index || 0
|
|
12
15
|
const mode = mpx.mode
|
|
13
16
|
const env = mpx.env
|
|
14
|
-
const defs = mpx.defs
|
|
15
|
-
const query = loaderUtils.getOptions(this) || {}
|
|
16
17
|
const filePath = this.resourcePath
|
|
17
18
|
const parts = parseComponent(content, {
|
|
18
19
|
filePath,
|
|
19
20
|
needMap: this.sourceMap,
|
|
20
21
|
mode,
|
|
21
|
-
defs,
|
|
22
22
|
env
|
|
23
23
|
})
|
|
24
|
-
let part = parts[
|
|
24
|
+
let part = parts[type]
|
|
25
25
|
if (Array.isArray(part)) {
|
|
26
|
-
part = part[
|
|
27
|
-
|
|
26
|
+
part = part[index]
|
|
27
|
+
}
|
|
28
|
+
if (!part) {
|
|
29
|
+
let content = ''
|
|
30
|
+
// 补全js内容
|
|
31
|
+
if (type === 'script') {
|
|
32
|
+
switch (ctorType) {
|
|
33
|
+
case 'app':
|
|
34
|
+
content += 'import {createApp} from "@mpxjs/core"\n' +
|
|
35
|
+
'createApp({})\n'
|
|
36
|
+
break
|
|
37
|
+
case 'page':
|
|
38
|
+
content += 'import {createPage} from "@mpxjs/core"\n' +
|
|
39
|
+
'createPage({})\n'
|
|
40
|
+
break
|
|
41
|
+
case 'component':
|
|
42
|
+
content += 'import {createComponent} from "@mpxjs/core"\n' +
|
|
43
|
+
'createComponent({})\n'
|
|
44
|
+
}
|
|
28
45
|
}
|
|
46
|
+
part = { content }
|
|
29
47
|
}
|
|
48
|
+
part = part || { content: '' }
|
|
30
49
|
this.callback(null, part.content, part.map)
|
|
31
50
|
}
|