@mpxjs/webpack-plugin 2.6.114-alpha.4 → 2.6.114-alpha.7
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/lib/{dependency → dependencies}/AddEntryDependency.js +0 -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 +864 -541
- package/lib/json-compiler/helper.js +156 -0
- package/lib/json-compiler/index.js +242 -451
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +137 -240
- 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/index.js +30 -4
- package/lib/record-loader.js +11 -0
- package/lib/{path-loader.js → resolve-loader.js} +0 -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/tenon-button.vue +1 -1
- package/lib/runtime/components/tenon/tenon-image.vue +1 -1
- package/lib/runtime/components/tenon/tenon-input.vue +1 -1
- package/lib/runtime/components/tenon/tenon-switch.vue +1 -1
- package/lib/runtime/components/tenon/tenon-text-area.vue +1 -1
- package/lib/runtime/components/tenon/tenon-text.vue +1 -1
- 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/selector.js +29 -10
- package/lib/style-compiler/index.js +15 -23
- 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/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 +95 -197
- package/lib/template-compiler/index.js +52 -139
- package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
- package/lib/tenon/index.js +1 -3
- package/lib/tenon/processScript.js +52 -40
- 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/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 +18 -20
- 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 -53
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import getInnerListeners from './getInnerListeners'
|
|
2
|
+
import getInnerListeners, { extendEvent } from './getInnerListeners'
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
name: 'mpx-image',
|
|
@@ -23,6 +23,13 @@
|
|
|
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
|
+
|
|
26
33
|
this.$emit('load', e)
|
|
27
34
|
}
|
|
28
35
|
this.image.onerror = (e) => {
|
|
@@ -38,14 +45,22 @@
|
|
|
38
45
|
}
|
|
39
46
|
},
|
|
40
47
|
render (createElement) {
|
|
41
|
-
if (this.mode === 'widthFix') {
|
|
48
|
+
if (this.mode === 'widthFix' || this.mode === 'heightFix') {
|
|
49
|
+
let style
|
|
50
|
+
if (this.mode === 'widthFix') {
|
|
51
|
+
style = {
|
|
52
|
+
height: 'auto'
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
style = {
|
|
56
|
+
width: 'auto'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
42
59
|
const domProps = {}
|
|
43
60
|
if (this.src) domProps.src = this.src
|
|
44
61
|
return createElement('img', {
|
|
45
62
|
domProps,
|
|
46
|
-
style
|
|
47
|
-
height: 'auto'
|
|
48
|
-
},
|
|
63
|
+
style,
|
|
49
64
|
class: ['mpx-image'],
|
|
50
65
|
on: getInnerListeners(this, { ignoredListeners: ['load', 'error'] })
|
|
51
66
|
})
|
|
@@ -85,6 +85,10 @@
|
|
|
85
85
|
animation: {
|
|
86
86
|
type: Boolean,
|
|
87
87
|
default: true
|
|
88
|
+
},
|
|
89
|
+
speed: {
|
|
90
|
+
type: Number,
|
|
91
|
+
default: 1000
|
|
88
92
|
}
|
|
89
93
|
},
|
|
90
94
|
watch: {
|
|
@@ -96,7 +100,7 @@
|
|
|
96
100
|
if (newVal < this.bs.maxScrollX) {
|
|
97
101
|
newVal = this.bs.maxScrollX
|
|
98
102
|
}
|
|
99
|
-
this.bs.scrollTo(newVal, this.bs.y)
|
|
103
|
+
this.bs.scrollTo(newVal, this.bs.y, this.speed)
|
|
100
104
|
},
|
|
101
105
|
y (newVal) {
|
|
102
106
|
this.source = ''
|
|
@@ -106,7 +110,7 @@
|
|
|
106
110
|
if (newVal < this.bs.maxScrollY) {
|
|
107
111
|
newVal = this.bs.maxScrollY
|
|
108
112
|
}
|
|
109
|
-
this.bs.scrollTo(this.bs.x, newVal)
|
|
113
|
+
this.bs.scrollTo(this.bs.x, newVal, this.speed)
|
|
110
114
|
},
|
|
111
115
|
scaleValue (newVal) {
|
|
112
116
|
this.isZooming = true
|
|
@@ -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
|
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
|
}
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
2
1
|
const postcss = require('postcss')
|
|
3
|
-
const loaderUtils = require('loader-utils')
|
|
4
2
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
5
|
-
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../
|
|
3
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
6
4
|
const trim = require('./plugins/trim')
|
|
7
5
|
const rpx = require('./plugins/rpx')
|
|
8
6
|
const vw = require('./plugins/vw')
|
|
9
7
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
10
8
|
const scopeId = require('./plugins/scope-id')
|
|
11
9
|
const transSpecial = require('./plugins/trans-special')
|
|
12
|
-
const matchCondition = require('../utils/match-condition')
|
|
10
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
13
11
|
const parseRequest = require('../utils/parse-request')
|
|
14
12
|
|
|
15
13
|
module.exports = function (css, map) {
|
|
16
14
|
this.cacheable()
|
|
17
15
|
const cb = this.async()
|
|
18
|
-
const loaderOptions = loaderUtils.getOptions(this) || {}
|
|
19
|
-
const mainCompilation = getMainCompilation(this._compilation)
|
|
20
|
-
const mpx = mainCompilation.__mpx__
|
|
21
|
-
const defs = mpx.defs
|
|
22
16
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
17
|
+
const mpx = this.getMpx()
|
|
18
|
+
const id = queryObj.moduleId || queryObj.mid || 'm' + mpx.pathHash(resourcePath)
|
|
19
|
+
const appInfo = mpx.appInfo
|
|
20
|
+
const defs = mpx.defs
|
|
21
|
+
const mode = mpx.mode
|
|
22
|
+
const isApp = resourcePath === appInfo.resourcePath
|
|
28
23
|
const transRpxRulesRaw = mpx.transRpxRules
|
|
29
|
-
|
|
30
24
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
31
25
|
|
|
32
26
|
const transRpxFn = mpx.webConfig && mpx.webConfig.transRpxFn
|
|
@@ -45,14 +39,12 @@ module.exports = function (css, map) {
|
|
|
45
39
|
},
|
|
46
40
|
config.options
|
|
47
41
|
)
|
|
48
|
-
// ali
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const moduleId = loaderOptions.moduleId || loaderOptions.mid
|
|
55
|
-
plugins.push(scopeId({ id: moduleId }))
|
|
42
|
+
// ali平台下处理scoped和host选择器
|
|
43
|
+
if (mode === 'ali') {
|
|
44
|
+
if (queryObj.scoped) {
|
|
45
|
+
plugins.push(scopeId({ id }))
|
|
46
|
+
}
|
|
47
|
+
plugins.push(transSpecial({ id }))
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
plugins.push(pluginCondStrip({
|
|
@@ -91,7 +83,7 @@ module.exports = function (css, map) {
|
|
|
91
83
|
.process(css, options)
|
|
92
84
|
.then(result => {
|
|
93
85
|
// ali环境添加全局样式抹平root差异
|
|
94
|
-
if (
|
|
86
|
+
if (mode === 'ali' && isApp) {
|
|
95
87
|
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
|
|
96
88
|
}
|
|
97
89
|
if (result.messages) {
|
|
@@ -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) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* 按平台条件编译CSS,用法如下:
|
|
5
3
|
* @type {postcss.Plugin<any>}
|
|
@@ -44,7 +42,7 @@ const postcss = require('postcss')
|
|
|
44
42
|
// @mpx-endif
|
|
45
43
|
// */
|
|
46
44
|
// `
|
|
47
|
-
module.exports =
|
|
45
|
+
module.exports = (options = {}) => {
|
|
48
46
|
const { defs } = options
|
|
49
47
|
|
|
50
48
|
const defKeys = Object.keys(defs)
|
|
@@ -91,71 +89,76 @@ module.exports = postcss.plugin('conditional-strip', (options = {}) => {
|
|
|
91
89
|
return parseCondition(/@mpx-elif[^(]*?\(([\s\S]*)\)/, content)
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
return {
|
|
93
|
+
postcssPlugin: 'conditional-strip',
|
|
94
|
+
Once (root) {
|
|
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
|
-
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]
|
|
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()
|
|
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
|
|
145
114
|
})
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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]
|
|
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()
|
|
150
|
+
}
|
|
150
151
|
}
|
|
151
|
-
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
if (!isKeyword) {
|
|
154
|
+
const curCond = currentConds[curDepth]
|
|
155
|
+
if (curCond && curCond.shouldRemove) {
|
|
156
|
+
curCond.children.push(node)
|
|
157
|
+
}
|
|
157
158
|
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
160
161
|
}
|
|
161
|
-
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports.postcss = true
|