@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
|
@@ -1,35 +1,29 @@
|
|
|
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
|
-
const transRpxFn = mpx.webConfig.transRpxFn
|
|
26
|
+
const transRpxFn = mpx.webConfig && mpx.webConfig.transRpxFn
|
|
33
27
|
const testResolveRange = (include = () => true, exclude) => {
|
|
34
28
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
35
29
|
}
|
|
@@ -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
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const postcss = require('postcss')
|
|
2
|
+
const rpxRegExp = /\b(\d+(\.\d+)?)rpx\b/
|
|
3
|
+
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
4
|
+
|
|
5
|
+
module.exports = postcss.plugin('hm', (options = {}) => root => {
|
|
6
|
+
function transHm (declaration) {
|
|
7
|
+
if (rpxRegExp.test(declaration.value)) {
|
|
8
|
+
declaration.value = declaration.value.replace(rpxRegExpG, function (match, $1) {
|
|
9
|
+
if ($1 === '0') return $1
|
|
10
|
+
return `${$1}hm`
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
root.walkRules(rule => {
|
|
16
|
+
rule.walkDecls(declaration => {
|
|
17
|
+
transHm(declaration)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const pxRegExp = /\b(\d+(\.\d+)?)px\b/
|
|
3
2
|
const pxRegExpG = /\b(\d+(\.\d+)?)px\b/g
|
|
3
|
+
// rpx
|
|
4
|
+
module.exports = (options = {}) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'rpx',
|
|
7
|
+
Once (root) {
|
|
8
|
+
const mode = options.mode || 'only'
|
|
9
|
+
const defaultIgnoreComment = mode === 'all' ? 'use px' : 'use rpx'
|
|
10
|
+
const baseWidth = 750
|
|
11
|
+
const designWidth = options.designWidth || 750
|
|
12
|
+
const ratio = +(baseWidth / designWidth).toFixed(2)
|
|
13
|
+
function isIgnoreComment (node) {
|
|
14
|
+
let result = node && node.type === 'comment' && node.text.trim() === (options.comment || defaultIgnoreComment)
|
|
15
|
+
if (result) {
|
|
16
|
+
node.remove()
|
|
17
|
+
}
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
4
20
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (result) {
|
|
14
|
-
node.remove()
|
|
15
|
-
}
|
|
16
|
-
return result
|
|
17
|
-
}
|
|
21
|
+
function transRpx (declaration) {
|
|
22
|
+
if (pxRegExp.test(declaration.value)) {
|
|
23
|
+
declaration.value = declaration.value.replace(pxRegExpG, function (match, $1) {
|
|
24
|
+
if ($1 === '0') return $1
|
|
25
|
+
return `${$1 * ratio}rpx`
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
root.walkRules(rule => {
|
|
31
|
+
let ignore = false
|
|
32
|
+
if (isIgnoreComment(rule.prev()) || isIgnoreComment(rule.last)) {
|
|
33
|
+
ignore = true
|
|
34
|
+
}
|
|
35
|
+
rule.walkDecls(declaration => {
|
|
36
|
+
if (ignore || isIgnoreComment(declaration.prev())) {
|
|
37
|
+
if (mode === 'only') {
|
|
38
|
+
transRpx(declaration)
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (mode === 'all') {
|
|
42
|
+
transRpx(declaration)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
24
46
|
})
|
|
25
47
|
}
|
|
26
48
|
}
|
|
49
|
+
}
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
let ignore = false
|
|
30
|
-
if (isIgnoreComment(rule.prev()) || isIgnoreComment(rule.last)) {
|
|
31
|
-
ignore = true
|
|
32
|
-
}
|
|
33
|
-
rule.walkDecls(declaration => {
|
|
34
|
-
if (ignore || isIgnoreComment(declaration.prev())) {
|
|
35
|
-
if (mode === 'only') {
|
|
36
|
-
transRpx(declaration)
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if (mode === 'all') {
|
|
40
|
-
transRpx(declaration)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
51
|
+
module.exports.postcss = true
|
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
|
+
// scope-id
|
|
3
3
|
|
|
4
|
-
module.exports =
|
|
5
|
-
|
|
4
|
+
module.exports = ({ id }) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'scope-id',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
const keyframes = Object.create(null)
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
node.selector = selectorParser(selectors => {
|
|
21
|
-
selectors.each(selector => {
|
|
22
|
-
let node = null
|
|
23
|
-
selector.each(n => {
|
|
24
|
-
// ">>>" combinator
|
|
25
|
-
if (n.type === 'combinator' && n.value === '>>>') {
|
|
26
|
-
n.value = ' '
|
|
27
|
-
n.spaces.before = n.spaces.after = ''
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
// /deep/ alias for >>>, since >>> doesn't work in SASS
|
|
31
|
-
if (n.type === 'tag' && n.value === '/deep/') {
|
|
32
|
-
const prev = n.prev()
|
|
33
|
-
if (prev && prev.type === 'combinator' && prev.value === ' ') {
|
|
34
|
-
prev.remove()
|
|
10
|
+
root.each(function rewriteSelector (node) {
|
|
11
|
+
if (!node.selector) {
|
|
12
|
+
// handle media queries
|
|
13
|
+
if (node.type === 'atrule') {
|
|
14
|
+
if (node.name === 'media' || node.name === 'supports') {
|
|
15
|
+
node.each(rewriteSelector)
|
|
16
|
+
} else if (/-?keyframes$/.test(node.name)) {
|
|
17
|
+
// register keyframes
|
|
18
|
+
keyframes[node.params] = node.params = node.params + '-' + id
|
|
35
19
|
}
|
|
36
|
-
n.remove()
|
|
37
|
-
return false
|
|
38
20
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
node.selector = selectorParser(selectors => {
|
|
24
|
+
selectors.each(selector => {
|
|
25
|
+
let node = null
|
|
26
|
+
selector.each(n => {
|
|
27
|
+
// ">>>" combinator
|
|
28
|
+
if (n.type === 'combinator' && n.value === '>>>') {
|
|
29
|
+
n.value = ' '
|
|
30
|
+
n.spaces.before = n.spaces.after = ''
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
// /deep/ alias for >>>, since >>> doesn't work in SASS
|
|
34
|
+
if (n.type === 'tag' && n.value === '/deep/') {
|
|
35
|
+
const prev = n.prev()
|
|
36
|
+
if (prev && prev.type === 'combinator' && prev.value === ' ') {
|
|
37
|
+
prev.remove()
|
|
38
|
+
}
|
|
39
|
+
n.remove()
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (n.type !== 'pseudo' && n.type !== 'combinator') {
|
|
43
|
+
node = n
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
// 对于page selector不添加scope id
|
|
47
|
+
if (node && node.type === 'tag' && node.value === 'page') return
|
|
48
|
+
selector.insertAfter(node, selectorParser.className({
|
|
49
|
+
value: id
|
|
50
|
+
}))
|
|
51
|
+
})
|
|
52
|
+
}).processSync(node.selector)
|
|
48
53
|
})
|
|
49
|
-
}).process(node.selector).result
|
|
50
|
-
})
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
// If keyframes are found in this <style>, find and rewrite animation names
|
|
56
|
+
// in declarations.
|
|
57
|
+
// Caveat: this only works for keyframes and animation rules in the same
|
|
58
|
+
// <style> element.
|
|
59
|
+
if (Object.keys(keyframes).length) {
|
|
60
|
+
root.walkDecls(decl => {
|
|
61
|
+
// individual animation-name declaration
|
|
62
|
+
if (/-?animation-name$/.test(decl.prop)) {
|
|
63
|
+
decl.value = decl.value.split(',')
|
|
64
|
+
.map(v => keyframes[v.trim()] || v.trim())
|
|
65
|
+
.join(',')
|
|
66
|
+
}
|
|
67
|
+
// shorthand
|
|
68
|
+
if (/-?animation$/.test(decl.prop)) {
|
|
69
|
+
decl.value = decl.value.split(',')
|
|
70
|
+
.map(v => {
|
|
71
|
+
const vals = v.trim().split(/\s+/)
|
|
72
|
+
const i = vals.findIndex(val => keyframes[val])
|
|
73
|
+
if (i !== -1) {
|
|
74
|
+
vals.splice(i, 1, keyframes[vals[i]])
|
|
75
|
+
return vals.join(' ')
|
|
76
|
+
} else {
|
|
77
|
+
return v
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.join(',')
|
|
81
|
+
}
|
|
82
|
+
})
|
|
78
83
|
}
|
|
79
|
-
}
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
|
-
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports.postcss = true
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
|
+
// trans-special
|
|
3
3
|
|
|
4
|
-
module.exports =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
selector
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
module.exports = ({ id }) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'trans-special',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
root.each(function rewriteSelector (node) {
|
|
9
|
+
if (!node.selector) return
|
|
10
|
+
node.selector = selectorParser(selectors => {
|
|
11
|
+
selectors.each(selector => {
|
|
12
|
+
selector.each(n => {
|
|
13
|
+
if (/^:host$/.test(n.value)) {
|
|
14
|
+
const compoundSelectors = n.nodes
|
|
15
|
+
n.replaceWith(selectorParser.className({
|
|
16
|
+
value: 'host-' + id
|
|
17
|
+
}))
|
|
18
|
+
selector.insertAfter(n, compoundSelectors)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
}).processSync(node.selector)
|
|
18
23
|
})
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports.postcss = true
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
|
|
3
|
-
module.exports =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
module.exports = (opts) => {
|
|
3
|
+
return {
|
|
4
|
+
postcssPlugin: 'trim',
|
|
5
|
+
Once: (root) => {
|
|
6
|
+
root.walk(({ type, raws }) => {
|
|
7
|
+
if (type === 'rule' || type === 'atrule') {
|
|
8
|
+
raws.before = raws.after = '\n'
|
|
9
|
+
}
|
|
10
|
+
})
|
|
7
11
|
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports.postcss = true
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const rpxRegExp = /\b(\d+(\.\d+)?)rpx\b/
|
|
3
2
|
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
4
3
|
|
|
5
|
-
module.exports =
|
|
6
|
-
|
|
4
|
+
module.exports = (options = {}) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'vw',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const transRpxFn = options.transRpxFn && typeof options.transRpxFn === 'function' ? options.transRpxFn : function (match, $1) {
|
|
11
|
+
if ($1 === '0') return $1
|
|
12
|
+
return `${$1 * rpx2vwRatio}vw`
|
|
13
|
+
}
|
|
14
|
+
function transVw (declaration) {
|
|
15
|
+
if (rpxRegExp.test(declaration.value)) {
|
|
16
|
+
declaration.value = declaration.value.replace(rpxRegExpG, transRpxFn)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
root.walkRules(rule => {
|
|
21
|
+
rule.walkDecls(declaration => {
|
|
22
|
+
transVw(declaration)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
15
25
|
}
|
|
16
26
|
}
|
|
27
|
+
}
|
|
17
28
|
|
|
18
|
-
|
|
19
|
-
rule.walkDecls(declaration => {
|
|
20
|
-
transVw(declaration)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
})
|
|
29
|
+
module.exports.postcss = true
|