Skip to content

Commit 549a1a7

Browse files
committed
rootValue for options.px2rem shouldn't be changed.
1 parent d530396 commit 549a1a7

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const precompile = require('weex-vue-precompiler')(/*optional config*/)
3939

4040
<!-- * `preservedTags`: the preserved weex components tag list. The default value is: `['a','container','div','image','img','text','input','switch','list','scroller','waterfall','slider','indicator','loading-indicator','loading','refresh','textarea','video','web']`. If you have other components as plugins installed in weex, you should add them to this lists, add pass the whole list to this. -->
4141
* `autoprefixer`: options for [autoprefixer](https://github.com/postcss/autoprefixer). default is { browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12'] }.
42-
* `px2rem`: options for [postcss-plugin-px2rem](https://github.com/ant-tool/postcss-plugin-px2rem). default is: { rootValue: 75 }.
42+
* `px2rem`: options for [postcss-plugin-px2rem](https://github.com/ant-tool/postcss-plugin-px2rem). default is: { rootValue: 75 }. (NOTICE: We shouldn't change the value of rootValue here. If you want to change the viewport width, you better use `<meta name="weex-viewport" content="...">` in your html entry file.)
4343
* `aliweex`: boolean. default is false. Tell whether aliweex components are included in your project.
4444

4545
## feature

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weex-vue-precompiler",
3-
"version": "0.1.18",
3+
"version": "0.1.19",
44
"description": "a precompiler for weex-vue-render.",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ const arrayMergeOpts = [
1010
'aliweexComponents'
1111
]
1212

13+
const mergeStrats = {
14+
px2rem: function (thisConfig, config) {
15+
const { px2rem } = config
16+
const { px2rem: thisPx2rem } = thisConfig
17+
if (px2rem) {
18+
for (k in px2rem) {
19+
if (k === 'rootValue') {
20+
// ignore rootValue. Always use 750. Why? We use meta[name=weex-viewport] and
21+
// meta.setViewport API to set design viewport width, and they would be broken if
22+
// we use other rootValue here.
23+
continue
24+
}
25+
else if (px2rem.hasOwnProperty(k)) {
26+
thisPx2rem[k] = px2rem[k]
27+
}
28+
}
29+
}
30+
return thisPx2rem
31+
}
32+
}
33+
1334
function mergeConfig(thisConfig, config) {
1435
if (config) {
1536
const {
@@ -22,7 +43,7 @@ function mergeConfig(thisConfig, config) {
2243
// merge all fields except arrays.
2344
for (const k in config) {
2445
if (arrayMergeOpts.indexOf(k) <= -1) {
25-
thisConfig[k] = config[k]
46+
thisConfig[k] = mergeStrats[k] ? mergeStrats[k](thisConfig, config): config[k]
2647
}
2748
}
2849

0 commit comments

Comments
 (0)