@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115
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/built-in-loader.js +49 -0
- package/lib/config.js +0 -14
- package/lib/content-loader.js +13 -0
- package/lib/dependency/ChildCompileDependency.js +24 -0
- package/lib/dependency/InjectDependency.js +26 -0
- package/lib/dependency/RemovedModuleDependency.js +23 -0
- package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
- package/lib/dependency/ResolveDependency.js +49 -0
- package/lib/extractor.js +178 -82
- package/lib/file-loader.js +19 -7
- package/lib/helpers.js +334 -39
- package/lib/index.js +525 -889
- package/lib/json-compiler/index.js +451 -245
- package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
- package/lib/loader.js +241 -178
- package/lib/native-loader.js +133 -71
- package/lib/parser.js +2 -1
- package/lib/path-loader.js +3 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +3 -2
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +3 -149
- package/lib/plugin-loader.js +287 -0
- package/lib/resolver/AddEnvPlugin.js +3 -4
- package/lib/resolver/AddModePlugin.js +3 -4
- package/lib/resolver/PackageEntryPlugin.js +36 -23
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/getInnerListeners.js +3 -1
- package/lib/runtime/components/web/mpx-image.vue +5 -20
- package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
- package/lib/runtime/components/web/mpx-swiper.vue +3 -18
- package/lib/runtime/i18n.wxs +11 -31
- package/lib/runtime/optionProcessor.js +3 -48
- package/lib/selector.js +10 -29
- package/lib/staticConfig.js +4 -0
- package/lib/style-compiler/index.js +24 -16
- package/lib/style-compiler/load-postcss-config.js +1 -3
- package/lib/style-compiler/plugins/conditional-strip.js +65 -68
- package/lib/style-compiler/plugins/rpx.js +37 -43
- package/lib/style-compiler/plugins/scope-id.js +72 -79
- package/lib/style-compiler/plugins/trans-special.js +18 -25
- package/lib/style-compiler/plugins/trim.js +7 -13
- package/lib/style-compiler/plugins/vw.js +16 -22
- package/lib/template-compiler/compiler.js +199 -106
- package/lib/template-compiler/index.js +139 -52
- package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
- package/lib/url-loader.js +29 -11
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/get-main-compilation.js +6 -0
- package/lib/utils/is-url-request.js +1 -10
- package/lib/utils/match-condition.js +1 -4
- package/lib/utils/normalize.js +15 -4
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/read-json-for-src.js +34 -0
- package/lib/utils/stringify-query.js +0 -4
- package/lib/utils/try-require.js +16 -0
- package/lib/web/processJSON.js +144 -113
- package/lib/web/processScript.js +34 -47
- package/lib/web/processTemplate.js +40 -57
- package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +8 -4
- package/lib/wxs/WxsTemplatePlugin.js +92 -46
- package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
- package/lib/wxs/wxs-loader.js +117 -0
- package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
- package/lib/wxss/getImportPrefix.js +30 -0
- package/lib/wxss/loader.js +43 -31
- package/lib/wxss/localsLoader.js +5 -1
- package/lib/wxss/processCss.js +103 -107
- package/package.json +18 -21
- package/LICENSE +0 -433
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/dependencies/AppEntryDependency.js +0 -58
- package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
- package/lib/dependencies/CommonJsVariableDependency.js +0 -81
- package/lib/dependencies/DynamicEntryDependency.js +0 -171
- package/lib/dependencies/FlagPluginDependency.js +0 -24
- package/lib/dependencies/InjectDependency.js +0 -43
- package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
- package/lib/dependencies/RecordIndependentDependency.js +0 -44
- package/lib/dependencies/RecordResourceMapDependency.js +0 -62
- package/lib/dependencies/RemoveEntryDependency.js +0 -40
- package/lib/dependencies/ResolveDependency.js +0 -88
- package/lib/independent-loader.js +0 -52
- package/lib/json-compiler/helper.js +0 -156
- package/lib/json-compiler/plugin.js +0 -150
- package/lib/partial-compile/index.js +0 -35
- package/lib/record-loader.js +0 -11
- package/lib/resolve-loader.js +0 -6
- package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
- package/lib/runtime/components/tenon/tenon-button.vue +0 -305
- package/lib/runtime/components/tenon/tenon-image.vue +0 -61
- package/lib/runtime/components/tenon/tenon-input.vue +0 -99
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
- package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
- package/lib/runtime/components/tenon/tenon-text.vue +0 -64
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/tenon/util.js +0 -44
- package/lib/runtime/optionProcessor.tenon.js +0 -386
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -105
- package/lib/tenon/processJSON.js +0 -360
- package/lib/tenon/processScript.js +0 -260
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -133
- package/lib/utils/const.js +0 -10
- package/lib/utils/emit-file.js +0 -10
- package/lib/utils/eval-json-js.js +0 -31
- package/lib/utils/get-entry-name.js +0 -13
- package/lib/utils/get-json-content.js +0 -42
- package/lib/utils/get-relative-path.js +0 -24
- package/lib/utils/resolve.js +0 -13
- package/lib/utils/set.js +0 -47
- package/lib/utils/stringify-loaders-resource.js +0 -25
- package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
- package/lib/wxs/loader.js +0 -142
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import getInnerListeners
|
|
2
|
+
import getInnerListeners from './getInnerListeners'
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
name: 'mpx-image',
|
|
@@ -23,13 +23,6 @@
|
|
|
23
23
|
beforeCreate () {
|
|
24
24
|
this.image = new Image()
|
|
25
25
|
this.image.onload = (e) => {
|
|
26
|
-
extendEvent(e, {
|
|
27
|
-
detail: {
|
|
28
|
-
width: this.image.width,
|
|
29
|
-
height: this.image.height
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
26
|
this.$emit('load', e)
|
|
34
27
|
}
|
|
35
28
|
this.image.onerror = (e) => {
|
|
@@ -45,22 +38,14 @@
|
|
|
45
38
|
}
|
|
46
39
|
},
|
|
47
40
|
render (createElement) {
|
|
48
|
-
if (this.mode === 'widthFix'
|
|
49
|
-
let style
|
|
50
|
-
if (this.mode === 'widthFix') {
|
|
51
|
-
style = {
|
|
52
|
-
height: 'auto'
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
style = {
|
|
56
|
-
width: 'auto'
|
|
57
|
-
}
|
|
58
|
-
}
|
|
41
|
+
if (this.mode === 'widthFix') {
|
|
59
42
|
const domProps = {}
|
|
60
43
|
if (this.src) domProps.src = this.src
|
|
61
44
|
return createElement('img', {
|
|
62
45
|
domProps,
|
|
63
|
-
style
|
|
46
|
+
style: {
|
|
47
|
+
height: 'auto'
|
|
48
|
+
},
|
|
64
49
|
class: ['mpx-image'],
|
|
65
50
|
on: getInnerListeners(this, { ignoredListeners: ['load', 'error'] })
|
|
66
51
|
})
|
|
@@ -85,10 +85,6 @@
|
|
|
85
85
|
animation: {
|
|
86
86
|
type: Boolean,
|
|
87
87
|
default: true
|
|
88
|
-
},
|
|
89
|
-
speed: {
|
|
90
|
-
type: Number,
|
|
91
|
-
default: 1000
|
|
92
88
|
}
|
|
93
89
|
},
|
|
94
90
|
watch: {
|
|
@@ -100,7 +96,7 @@
|
|
|
100
96
|
if (newVal < this.bs.maxScrollX) {
|
|
101
97
|
newVal = this.bs.maxScrollX
|
|
102
98
|
}
|
|
103
|
-
this.bs.scrollTo(newVal, this.bs.y
|
|
99
|
+
this.bs.scrollTo(newVal, this.bs.y)
|
|
104
100
|
},
|
|
105
101
|
y (newVal) {
|
|
106
102
|
this.source = ''
|
|
@@ -110,7 +106,7 @@
|
|
|
110
106
|
if (newVal < this.bs.maxScrollY) {
|
|
111
107
|
newVal = this.bs.maxScrollY
|
|
112
108
|
}
|
|
113
|
-
this.bs.scrollTo(this.bs.x, newVal
|
|
109
|
+
this.bs.scrollTo(this.bs.x, newVal)
|
|
114
110
|
},
|
|
115
111
|
scaleValue (newVal) {
|
|
116
112
|
this.isZooming = true
|
|
@@ -41,9 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
data () {
|
|
43
43
|
return {
|
|
44
|
-
currentIndex: this.current
|
|
45
|
-
currentChildLength: 0,
|
|
46
|
-
lastChildLength: 0
|
|
44
|
+
currentIndex: this.current
|
|
47
45
|
}
|
|
48
46
|
},
|
|
49
47
|
computed: {
|
|
@@ -83,9 +81,6 @@
|
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
83
|
},
|
|
86
|
-
updated () {
|
|
87
|
-
this.currentChildLength = this.$children && this.$children.length
|
|
88
|
-
},
|
|
89
84
|
watch: {
|
|
90
85
|
current (val) {
|
|
91
86
|
if (this.bs) {
|
|
@@ -94,15 +89,6 @@
|
|
|
94
89
|
}
|
|
95
90
|
this.changeSource = ''
|
|
96
91
|
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
|
|
106
92
|
}
|
|
107
93
|
},
|
|
108
94
|
activated () {
|
|
@@ -181,11 +167,10 @@
|
|
|
181
167
|
refresh () {
|
|
182
168
|
this.bs && this.bs.refresh()
|
|
183
169
|
},
|
|
184
|
-
goto (index
|
|
170
|
+
goto (index) {
|
|
185
171
|
const x = this.vertical ? 0 : index
|
|
186
172
|
const y = this.vertical ? index : 0
|
|
187
|
-
|
|
188
|
-
this.bs && this.bs.goToPage(x, y, speed)
|
|
173
|
+
this.bs && this.bs.goToPage(x, y)
|
|
189
174
|
}
|
|
190
175
|
},
|
|
191
176
|
render (createElement) {
|
package/lib/runtime/i18n.wxs
CHANGED
|
@@ -6,6 +6,7 @@ function genRegExp (str, flags) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
function likeArray (arr) {
|
|
10
11
|
if (!__mpx_wxs__) {
|
|
11
12
|
return Array.isArray(arr)
|
|
@@ -22,6 +23,7 @@ function isDef (v) {
|
|
|
22
23
|
return v !== undefined && v !== null
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
|
|
25
27
|
var RE_TOKEN_LIST_VALUE = genRegExp('^[0-9]+')
|
|
26
28
|
var RE_TOKEN_NAMED_VALUE = genRegExp('^[A-Za-z0-9_]+')
|
|
27
29
|
|
|
@@ -38,10 +40,7 @@ function parseMessage (format) {
|
|
|
38
40
|
var char = format[position++]
|
|
39
41
|
if (char === '{') {
|
|
40
42
|
if (text) {
|
|
41
|
-
tokens.push({
|
|
42
|
-
type: 'text',
|
|
43
|
-
value: text
|
|
44
|
-
})
|
|
43
|
+
tokens.push({ type: 'text', value: text })
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
text = ''
|
|
@@ -57,10 +56,7 @@ function parseMessage (format) {
|
|
|
57
56
|
: isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
|
|
58
57
|
? 'named'
|
|
59
58
|
: 'unknown'
|
|
60
|
-
tokens.push({
|
|
61
|
-
value: sub,
|
|
62
|
-
type: type
|
|
63
|
-
})
|
|
59
|
+
tokens.push({ value: sub, type: type })
|
|
64
60
|
} else if (char === '%') {
|
|
65
61
|
// when found rails i18n syntax, skip text capture
|
|
66
62
|
if (format[(position)] !== '{') {
|
|
@@ -71,10 +67,7 @@ function parseMessage (format) {
|
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
text && tokens.push({
|
|
75
|
-
type: 'text',
|
|
76
|
-
value: text
|
|
77
|
-
})
|
|
70
|
+
text && tokens.push({ type: 'text', value: text })
|
|
78
71
|
|
|
79
72
|
return tokens
|
|
80
73
|
}
|
|
@@ -270,24 +263,19 @@ function exist (messages, locale, key) {
|
|
|
270
263
|
var messages = {}
|
|
271
264
|
var dateTimeFormats = {}
|
|
272
265
|
var numberFormats = {}
|
|
273
|
-
var locale = 'zh-CN'
|
|
274
|
-
|
|
275
|
-
function getLocale () {
|
|
276
|
-
return __mpx_locale__ || locale
|
|
277
|
-
}
|
|
278
266
|
|
|
279
267
|
function getMessages () {
|
|
280
|
-
// __mpx_messages__会在编译时通过lib/wxs/i18n-loader注入
|
|
268
|
+
// __mpx_messages__会在编译时通过lib/wxs/wxs-i18n-loader注入
|
|
281
269
|
return __mpx_messages__ || messages
|
|
282
270
|
}
|
|
283
271
|
|
|
284
272
|
function getDateTimeFormats () {
|
|
285
|
-
// __mpx_datetime_formats__会在编译时通过lib/wxs/i18n-loader注入
|
|
273
|
+
// __mpx_datetime_formats__会在编译时通过lib/wxs/wxs-i18n-loader注入
|
|
286
274
|
return __mpx_datetime_formats__ || dateTimeFormats
|
|
287
275
|
}
|
|
288
276
|
|
|
289
277
|
function getNumberFormats () {
|
|
290
|
-
// __mpx_number_formats__会在编译时通过lib/wxs/i18n-loader注入
|
|
278
|
+
// __mpx_number_formats__会在编译时通过lib/wxs/wxs-i18n-loader注入
|
|
291
279
|
return __mpx_number_formats__ || numberFormats
|
|
292
280
|
}
|
|
293
281
|
|
|
@@ -351,15 +339,7 @@ module.exports = {
|
|
|
351
339
|
}
|
|
352
340
|
|
|
353
341
|
if (!__mpx_wxs__) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
version: 0
|
|
358
|
-
}
|
|
359
|
-
global.i18nMethods = Object.assign(module.exports, {
|
|
360
|
-
__getMessages: getMessages,
|
|
361
|
-
__getDateTimeFormats: getDateTimeFormats,
|
|
362
|
-
__getNumberFormats: getNumberFormats
|
|
363
|
-
})
|
|
364
|
-
}
|
|
342
|
+
module.exports.__getMessages = getMessages
|
|
343
|
+
module.exports.__getDateTimeFormats = getDateTimeFormats
|
|
344
|
+
module.exports.__getNumberFormats = getNumberFormats
|
|
365
345
|
}
|
|
@@ -4,7 +4,7 @@ export default function processOption (
|
|
|
4
4
|
option,
|
|
5
5
|
ctorType,
|
|
6
6
|
firstPage,
|
|
7
|
-
|
|
7
|
+
componentId,
|
|
8
8
|
pageConfig,
|
|
9
9
|
pagesMap,
|
|
10
10
|
componentsMap,
|
|
@@ -85,51 +85,6 @@ 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
|
-
|
|
133
88
|
const routes = []
|
|
134
89
|
|
|
135
90
|
for (const pagePath in pagesMap) {
|
|
@@ -384,8 +339,8 @@ registered in parent context!`)
|
|
|
384
339
|
option.mixins = [mixin]
|
|
385
340
|
}
|
|
386
341
|
|
|
387
|
-
if (
|
|
388
|
-
option.componentPath = '/' +
|
|
342
|
+
if (componentId) {
|
|
343
|
+
option.componentPath = '/' + componentId
|
|
389
344
|
}
|
|
390
345
|
|
|
391
346
|
return option
|
package/lib/selector.js
CHANGED
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
const parseComponent = require('./parser')
|
|
2
|
-
const
|
|
2
|
+
const loaderUtils = require('loader-utils')
|
|
3
|
+
const getMainCompilation = require('./utils/get-main-compilation')
|
|
3
4
|
|
|
4
5
|
module.exports = function (content) {
|
|
5
6
|
this.cacheable()
|
|
6
|
-
|
|
7
|
-
const mpx =
|
|
7
|
+
const mainCompilation = getMainCompilation(this._compilation)
|
|
8
|
+
const mpx = mainCompilation.__mpx__
|
|
8
9
|
if (!mpx) {
|
|
9
10
|
return content
|
|
10
11
|
}
|
|
11
|
-
const { queryObj } = parseRequest(this.resource)
|
|
12
|
-
const ctorType = queryObj.ctorType
|
|
13
|
-
const type = queryObj.type
|
|
14
|
-
const index = queryObj.index || 0
|
|
15
12
|
const mode = mpx.mode
|
|
16
13
|
const env = mpx.env
|
|
14
|
+
const defs = mpx.defs
|
|
15
|
+
const query = loaderUtils.getOptions(this) || {}
|
|
17
16
|
const filePath = this.resourcePath
|
|
18
17
|
const parts = parseComponent(content, {
|
|
19
18
|
filePath,
|
|
20
19
|
needMap: this.sourceMap,
|
|
21
20
|
mode,
|
|
21
|
+
defs,
|
|
22
22
|
env
|
|
23
23
|
})
|
|
24
|
-
let part = parts[type]
|
|
24
|
+
let part = parts[query.type] || {}
|
|
25
25
|
if (Array.isArray(part)) {
|
|
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
|
-
}
|
|
26
|
+
part = part[query.index] || {
|
|
27
|
+
content: ''
|
|
45
28
|
}
|
|
46
|
-
part = { content }
|
|
47
29
|
}
|
|
48
|
-
part = part || { content: '' }
|
|
49
30
|
this.callback(null, part.content, part.map)
|
|
50
31
|
}
|
|
@@ -1,29 +1,35 @@
|
|
|
1
|
+
const getMainCompilation = require('../utils/get-main-compilation')
|
|
1
2
|
const postcss = require('postcss')
|
|
3
|
+
const loaderUtils = require('loader-utils')
|
|
2
4
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
3
|
-
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../
|
|
5
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../staticConfig')
|
|
4
6
|
const trim = require('./plugins/trim')
|
|
5
7
|
const rpx = require('./plugins/rpx')
|
|
6
8
|
const vw = require('./plugins/vw')
|
|
7
9
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
8
10
|
const scopeId = require('./plugins/scope-id')
|
|
9
11
|
const transSpecial = require('./plugins/trans-special')
|
|
10
|
-
const
|
|
12
|
+
const matchCondition = require('../utils/match-condition')
|
|
11
13
|
const parseRequest = require('../utils/parse-request')
|
|
12
14
|
|
|
13
15
|
module.exports = function (css, map) {
|
|
14
16
|
this.cacheable()
|
|
15
17
|
const cb = this.async()
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const appInfo = mpx.appInfo
|
|
18
|
+
const loaderOptions = loaderUtils.getOptions(this) || {}
|
|
19
|
+
const mainCompilation = getMainCompilation(this._compilation)
|
|
20
|
+
const mpx = mainCompilation.__mpx__
|
|
20
21
|
const defs = mpx.defs
|
|
21
|
-
const
|
|
22
|
-
const
|
|
22
|
+
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
23
|
+
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
24
|
+
const componentsMap = mpx.componentsMap[packageName]
|
|
25
|
+
const pagesMap = mpx.pagesMap
|
|
26
|
+
const isApp = (!componentsMap[resourcePath] && !pagesMap[resourcePath])
|
|
27
|
+
|
|
23
28
|
const transRpxRulesRaw = mpx.transRpxRules
|
|
29
|
+
|
|
24
30
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
25
31
|
|
|
26
|
-
const transRpxFn = mpx.webConfig
|
|
32
|
+
const transRpxFn = mpx.webConfig.transRpxFn
|
|
27
33
|
const testResolveRange = (include = () => true, exclude) => {
|
|
28
34
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
29
35
|
}
|
|
@@ -39,12 +45,14 @@ module.exports = function (css, map) {
|
|
|
39
45
|
},
|
|
40
46
|
config.options
|
|
41
47
|
)
|
|
42
|
-
// ali
|
|
43
|
-
if (mode === 'ali') {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
// ali环境处理host选择器
|
|
49
|
+
if (mpx.mode === 'ali') {
|
|
50
|
+
plugins.push(transSpecial({ id: loaderOptions.moduleId || loaderOptions.mid }))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (loaderOptions.scoped) {
|
|
54
|
+
const moduleId = loaderOptions.moduleId || loaderOptions.mid
|
|
55
|
+
plugins.push(scopeId({ id: moduleId }))
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
plugins.push(pluginCondStrip({
|
|
@@ -83,7 +91,7 @@ module.exports = function (css, map) {
|
|
|
83
91
|
.process(css, options)
|
|
84
92
|
.then(result => {
|
|
85
93
|
// ali环境添加全局样式抹平root差异
|
|
86
|
-
if (mode === 'ali' && isApp) {
|
|
94
|
+
if (mpx.mode === 'ali' && isApp) {
|
|
87
95
|
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
|
|
88
96
|
}
|
|
89
97
|
if (result.messages) {
|
|
@@ -16,9 +16,7 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
16
16
|
webpack: loaderContext,
|
|
17
17
|
defs: inlineConfig.defs || {}
|
|
18
18
|
}
|
|
19
|
-
loaded = load(ctx, config.path, {
|
|
20
|
-
loaders: { '.json': (_, content) => JSON.parse(content) }
|
|
21
|
-
}).catch(err => {
|
|
19
|
+
loaded = load(ctx, config.path, { argv: false }).catch(err => {
|
|
22
20
|
// postcss-load-config throws error when no config file is found,
|
|
23
21
|
// but for us it's optional. only emit other errors
|
|
24
22
|
if (err.message.indexOf('No PostCSS Config found') >= 0) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const postcss = require('postcss')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 按平台条件编译CSS,用法如下:
|
|
3
5
|
* @type {postcss.Plugin<any>}
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
// @mpx-endif
|
|
43
45
|
// */
|
|
44
46
|
// `
|
|
45
|
-
module.exports = (options = {}) => {
|
|
47
|
+
module.exports = postcss.plugin('conditional-strip', (options = {}) => {
|
|
46
48
|
const { defs } = options
|
|
47
49
|
|
|
48
50
|
const defKeys = Object.keys(defs)
|
|
@@ -89,76 +91,71 @@ module.exports = (options = {}) => {
|
|
|
89
91
|
return parseCondition(/@mpx-elif[^(]*?\(([\s\S]*)\)/, content)
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const currentConds = []
|
|
97
|
-
let curDepth = -1
|
|
94
|
+
return function (root, result) {
|
|
95
|
+
const condsStacks = []
|
|
96
|
+
const currentConds = []
|
|
97
|
+
let curDepth = -1
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
const parentCond = currentConds[curDepth - 1]
|
|
134
|
-
if (parentCond && parentCond.shouldRemove) {
|
|
135
|
-
cond.shouldRemove = true
|
|
136
|
-
}
|
|
137
|
-
condsStacks[curDepth].else = cond
|
|
138
|
-
currentConds[curDepth] = cond
|
|
139
|
-
} else if (isEndIf(text)) {
|
|
140
|
-
isKeyword = true
|
|
141
|
-
const curConds = condsStacks.pop()
|
|
142
|
-
Object.keys(curConds).forEach(k => {
|
|
143
|
-
curConds[k].children.forEach(node => {
|
|
144
|
-
node.remove()
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
currentConds.pop()
|
|
148
|
-
curDepth--
|
|
149
|
-
node.remove()
|
|
99
|
+
root.walk(node => {
|
|
100
|
+
let isKeyword = false
|
|
101
|
+
if (node.type === 'comment') {
|
|
102
|
+
const { text } = node
|
|
103
|
+
if (isIfStart(text)) {
|
|
104
|
+
isKeyword = true
|
|
105
|
+
const cond = parseIf(text)
|
|
106
|
+
curDepth++
|
|
107
|
+
const parentCond = currentConds[curDepth - 1]
|
|
108
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
109
|
+
cond.shouldRemove = true
|
|
110
|
+
}
|
|
111
|
+
cond.children.push(node)
|
|
112
|
+
condsStacks.push({
|
|
113
|
+
if: cond
|
|
114
|
+
})
|
|
115
|
+
currentConds[curDepth] = cond
|
|
116
|
+
} else if (isElseIf(text)) {
|
|
117
|
+
isKeyword = true
|
|
118
|
+
const cond = parseElseIf(text)
|
|
119
|
+
const parentCond = currentConds[curDepth - 1]
|
|
120
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
121
|
+
cond.shouldRemove = true
|
|
122
|
+
}
|
|
123
|
+
cond.children.push(node)
|
|
124
|
+
condsStacks[curDepth].elif = cond
|
|
125
|
+
currentConds[curDepth] = cond
|
|
126
|
+
} else if (isElse(text)) {
|
|
127
|
+
isKeyword = true
|
|
128
|
+
const curConds = condsStacks[curDepth]
|
|
129
|
+
const cond = {
|
|
130
|
+
shouldRemove: !(curConds.if.shouldRemove && (!curConds.elif || curConds.elif.shouldRemove)),
|
|
131
|
+
children: [node]
|
|
150
132
|
}
|
|
133
|
+
const parentCond = currentConds[curDepth - 1]
|
|
134
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
135
|
+
cond.shouldRemove = true
|
|
136
|
+
}
|
|
137
|
+
condsStacks[curDepth].else = cond
|
|
138
|
+
currentConds[curDepth] = cond
|
|
139
|
+
} else if (isEndIf(text)) {
|
|
140
|
+
isKeyword = true
|
|
141
|
+
const curConds = condsStacks.pop()
|
|
142
|
+
Object.keys(curConds).forEach(k => {
|
|
143
|
+
curConds[k].children.forEach(node => {
|
|
144
|
+
node.remove()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
currentConds.pop()
|
|
148
|
+
curDepth--
|
|
149
|
+
node.remove()
|
|
151
150
|
}
|
|
151
|
+
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
153
|
+
if (!isKeyword) {
|
|
154
|
+
const curCond = currentConds[curDepth]
|
|
155
|
+
if (curCond && curCond.shouldRemove) {
|
|
156
|
+
curCond.children.push(node)
|
|
158
157
|
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
161
160
|
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
module.exports.postcss = true
|
|
161
|
+
})
|