@mpxjs/webpack-plugin 2.7.0-alpha.0 → 2.7.0-alpha.2
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/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +13 -6
- package/lib/dependencies/DynamicEntryDependency.js +85 -41
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +11 -6
- package/lib/extractor.js +17 -7
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +6 -12
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +595 -304
- package/lib/json-compiler/helper.js +36 -32
- package/lib/json-compiler/index.js +119 -66
- package/lib/json-compiler/plugin.js +23 -7
- package/lib/loader.js +135 -90
- package/lib/native-loader.js +37 -69
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +8 -3
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +17 -5
- 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/navigator.js +1 -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/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 +2 -2
- package/lib/resolve-loader.js +4 -1
- 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 +51 -45
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +37 -8
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/runtime/optionProcessor.js +50 -20
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/runtime/stringify.wxs +6 -4
- package/lib/selector.js +23 -5
- package/lib/style-compiler/index.js +12 -13
- 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 +19 -12
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +172 -62
- package/lib/template-compiler/index.js +8 -9
- package/lib/template-compiler/trans-dynamic-class-expr.js +32 -22
- 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/utils/const.js +6 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +3 -3
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -2
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +45 -38
- package/lib/web/processTemplate.js +56 -41
- package/lib/wxml/loader.js +1 -6
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxs/i18n-loader.js +5 -4
- package/lib/wxs/loader.js +87 -56
- package/lib/wxs/pre-loader.js +30 -10
- package/lib/wxss/loader.js +3 -3
- package/lib/wxss/processCss.js +135 -131
- package/package.json +23 -17
- package/lib/built-in-loader.js +0 -49
- package/lib/dependencies/RecordStaticResourceDependency.js +0 -47
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
|
@@ -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
|
+
}
|
|
@@ -93,7 +93,7 @@ function isDef (v) {
|
|
|
93
93
|
return v !== undefined && v !== null
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
function
|
|
96
|
+
function stringifyDynamicClass (value) {
|
|
97
97
|
if (!value) return ''
|
|
98
98
|
if (likeArray(value)) {
|
|
99
99
|
return stringifyArray(value)
|
|
@@ -111,7 +111,7 @@ function stringifyArray (value) {
|
|
|
111
111
|
var res = ''
|
|
112
112
|
var stringified
|
|
113
113
|
for (var i = 0; i < value.length; i++) {
|
|
114
|
-
if (isDef(stringified =
|
|
114
|
+
if (isDef(stringified = stringifyDynamicClass(value[i])) && stringified !== '') {
|
|
115
115
|
if (res) res += ' '
|
|
116
116
|
res += stringified
|
|
117
117
|
}
|
|
@@ -120,6 +120,8 @@ function stringifyArray (value) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
var mpxDashReg = genRegExp('(.+)MpxDash$')
|
|
123
|
+
// 转义字符在wxs正则中存在平台兼容性问题,用[$]规避使用转义字符
|
|
124
|
+
var mpxDashReplaceReg = genRegExp('[$]', 'g')
|
|
123
125
|
|
|
124
126
|
function stringifyObject (value) {
|
|
125
127
|
var res = ''
|
|
@@ -129,7 +131,7 @@ function stringifyObject (value) {
|
|
|
129
131
|
if (value[key]) {
|
|
130
132
|
if (res) res += ' '
|
|
131
133
|
if (mpxDashReg.test(key)) {
|
|
132
|
-
key =
|
|
134
|
+
key = mpxDashReg.exec(key)[1].replace(mpxDashReplaceReg, '-')
|
|
133
135
|
}
|
|
134
136
|
res += key
|
|
135
137
|
}
|
|
@@ -207,7 +209,7 @@ module.exports = {
|
|
|
207
209
|
if (typeof staticClass !== 'string') {
|
|
208
210
|
return console.log('Template attr class must be a string!')
|
|
209
211
|
}
|
|
210
|
-
return concat(staticClass,
|
|
212
|
+
return concat(staticClass, stringifyDynamicClass(dynamicClass))
|
|
211
213
|
},
|
|
212
214
|
stringifyStyle: function (staticStyle, dynamicStyle) {
|
|
213
215
|
var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle)
|
package/lib/selector.js
CHANGED
|
@@ -9,24 +9,42 @@ module.exports = function (content) {
|
|
|
9
9
|
return content
|
|
10
10
|
}
|
|
11
11
|
const { queryObj } = parseRequest(this.resource)
|
|
12
|
+
const ctorType = queryObj.ctorType
|
|
12
13
|
const type = queryObj.type
|
|
13
14
|
const index = queryObj.index || 0
|
|
14
15
|
const mode = mpx.mode
|
|
15
16
|
const env = mpx.env
|
|
16
|
-
const defs = mpx.defs
|
|
17
17
|
const filePath = this.resourcePath
|
|
18
18
|
const parts = parseComponent(content, {
|
|
19
19
|
filePath,
|
|
20
20
|
needMap: this.sourceMap,
|
|
21
21
|
mode,
|
|
22
|
-
defs,
|
|
23
22
|
env
|
|
24
23
|
})
|
|
25
|
-
let part = parts[type]
|
|
24
|
+
let part = parts[type]
|
|
26
25
|
if (Array.isArray(part)) {
|
|
27
|
-
part = part[index]
|
|
28
|
-
|
|
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
|
+
}
|
|
29
45
|
}
|
|
46
|
+
part = { content }
|
|
30
47
|
}
|
|
48
|
+
part = part || { content: '' }
|
|
31
49
|
this.callback(null, part.content, part.map)
|
|
32
50
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
const postcss = require('postcss')
|
|
2
2
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
3
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
3
4
|
const trim = require('./plugins/trim')
|
|
4
5
|
const rpx = require('./plugins/rpx')
|
|
5
6
|
const vw = require('./plugins/vw')
|
|
6
7
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
7
8
|
const scopeId = require('./plugins/scope-id')
|
|
8
9
|
const transSpecial = require('./plugins/trans-special')
|
|
9
|
-
const matchCondition = require('../utils/match-condition')
|
|
10
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
10
11
|
const parseRequest = require('../utils/parse-request')
|
|
11
12
|
|
|
12
13
|
module.exports = function (css, map) {
|
|
13
14
|
this.cacheable()
|
|
14
15
|
const cb = this.async()
|
|
15
16
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
16
|
-
const id = queryObj.moduleId || queryObj.mid
|
|
17
17
|
const mpx = this.getMpx()
|
|
18
|
+
const id = queryObj.moduleId || queryObj.mid || 'm' + mpx.pathHash(resourcePath)
|
|
19
|
+
const appInfo = mpx.appInfo
|
|
18
20
|
const defs = mpx.defs
|
|
19
21
|
const mode = mpx.mode
|
|
20
|
-
const
|
|
21
|
-
const componentsMap = mpx.componentsMap[packageName]
|
|
22
|
-
const pagesMap = mpx.pagesMap
|
|
23
|
-
const isApp = !(pagesMap[resourcePath] || componentsMap[resourcePath])
|
|
22
|
+
const isApp = resourcePath === appInfo.resourcePath
|
|
24
23
|
const transRpxRulesRaw = mpx.transRpxRules
|
|
25
24
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
26
25
|
|
|
26
|
+
const transRpxFn = mpx.webConfig && mpx.webConfig.transRpxFn
|
|
27
27
|
const testResolveRange = (include = () => true, exclude) => {
|
|
28
28
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
29
29
|
}
|
|
@@ -39,15 +39,14 @@ module.exports = function (css, map) {
|
|
|
39
39
|
},
|
|
40
40
|
config.options
|
|
41
41
|
)
|
|
42
|
-
// ali
|
|
42
|
+
// ali平台下处理scoped和host选择器
|
|
43
43
|
if (mode === 'ali') {
|
|
44
|
+
if (queryObj.scoped) {
|
|
45
|
+
plugins.push(scopeId({ id }))
|
|
46
|
+
}
|
|
44
47
|
plugins.push(transSpecial({ id }))
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
if (queryObj.scoped) {
|
|
48
|
-
plugins.push(scopeId({ id }))
|
|
49
|
-
}
|
|
50
|
-
|
|
51
50
|
plugins.push(pluginCondStrip({
|
|
52
51
|
defs
|
|
53
52
|
}))
|
|
@@ -69,7 +68,7 @@ module.exports = function (css, map) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
if (mpx.mode === 'web') {
|
|
72
|
-
plugins.push(vw)
|
|
71
|
+
plugins.push(vw({ transRpxFn }))
|
|
73
72
|
}
|
|
74
73
|
// source map
|
|
75
74
|
if (this.sourceMap && !options.map) {
|
|
@@ -85,7 +84,7 @@ module.exports = function (css, map) {
|
|
|
85
84
|
.then(result => {
|
|
86
85
|
// ali环境添加全局样式抹平root差异
|
|
87
86
|
if (mode === 'ali' && isApp) {
|
|
88
|
-
result.css +=
|
|
87
|
+
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
|
|
89
88
|
}
|
|
90
89
|
if (result.messages) {
|
|
91
90
|
result.messages.forEach(({ type, file }) => {
|
|
@@ -16,7 +16,9 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
16
16
|
webpack: loaderContext,
|
|
17
17
|
defs: inlineConfig.defs || {}
|
|
18
18
|
}
|
|
19
|
-
loaded = load(ctx, config.path, {
|
|
19
|
+
loaded = load(ctx, config.path, {
|
|
20
|
+
loaders: { '.json': (_, content) => JSON.parse(content) }
|
|
21
|
+
}).catch(err => {
|
|
20
22
|
// postcss-load-config throws error when no config file is found,
|
|
21
23
|
// but for us it's optional. only emit other errors
|
|
22
24
|
if (err.message.indexOf('No PostCSS Config found') >= 0) {
|