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