Skip to content

Commit 4e88451

Browse files
author
luoxue
committed
feat(autoprefixer): css 自动添加前缀
1 parent 53616f8 commit 4e88451

File tree

6 files changed

+69
-3
lines changed

6 files changed

+69
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
### 🌟 新功能
44

55
* **课题2:** 完成基本构建,js、css打包进html,实现dev跟build环境 ([71a6a19](https://github.com/luoxue-victor/learn_webpack/commit/71a6a19))
6+
* **新增loader配置:** 增加ts、css、less、sass、postcss、babel配置 ([53616f8](https://github.com/luoxue-victor/learn_webpack/commit/53616f8))
67
* **修改了配置文件:** i feat a config ([382c60c](https://github.com/luoxue-victor/learn_webpack/commit/382c60c))
78
* **all:** 初始化一个项目 ([336cc13](https://github.com/luoxue-victor/learn_webpack/commit/336cc13))
89
* **asdasdasdas:** 你爱哈的 ([ea12f9c](https://github.com/luoxue-victor/learn_webpack/commit/ea12f9c))
910
* **config:** add config option ([83c9f1e](https://github.com/luoxue-victor/learn_webpack/commit/83c9f1e))
1011
* **daasd:** asdasd ([0b6ee85](https://github.com/luoxue-victor/learn_webpack/commit/0b6ee85))
11-
* **feat:** aaaaa ([73abf42](https://github.com/luoxue-victor/learn_webpack/commit/73abf42))
12+
* **feat:** asdada ([64090c7](https://github.com/luoxue-victor/learn_webpack/commit/64090c7))
1213
* **init:** 项目初始化 ([d7835fb](https://github.com/luoxue-victor/learn_webpack/commit/d7835fb))
1314
* **webpack:** webpack配置 ([9a1d29c](https://github.com/luoxue-victor/learn_webpack/commit/9a1d29c))
1415
* 你好 ([6e534da](https://github.com/luoxue-victor/learn_webpack/commit/6e534da))
1516
* asasdasasd ([8f9515f](https://github.com/luoxue-victor/learn_webpack/commit/8f9515f))
1617
* asd ([d278787](https://github.com/luoxue-victor/learn_webpack/commit/d278787))
17-
* **feat:** asdada ([64090c7](https://github.com/luoxue-victor/learn_webpack/commit/64090c7))
18+
* **feat:** aaaaa ([73abf42](https://github.com/luoxue-victor/learn_webpack/commit/73abf42))
1819

1920

2021
### 🐛 Bug 修复

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,4 +606,54 @@ dist/app.css
606606
background: green;
607607
height: 26.66667vw;
608608
}
609+
```
610+
611+
### 配置 autoprefixer
612+
613+
自动添加 css 前缀
614+
615+
postcss.config.js
616+
617+
```js
618+
module.exports = {
619+
plugins: {
620+
autoprefixer: {
621+
overrideBrowserslist: [
622+
'> 1%',
623+
'last 3 versions',
624+
'iOS >= 8',
625+
'Android >= 4',
626+
'Chrome >= 40'
627+
]
628+
}
629+
}
630+
}
631+
```
632+
633+
效果
634+
635+
``` css
636+
/* index.css */
637+
.test {
638+
width: 200px;
639+
height: 200px;
640+
color: red;
641+
display: flex;
642+
background-color: orange;
643+
}
644+
```
645+
转换后
646+
647+
``` css
648+
/* index.css */
649+
.test {
650+
width: 26.66667vw;
651+
height: 26.66667vw;
652+
color: red;
653+
display: -webkit-box;
654+
display: -webkit-flex;
655+
display: -ms-flexbox;
656+
display: flex;
657+
background-color: orange;
658+
}
609659
```

dist/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
width: 26.66667vw;
44
height: 26.66667vw;
55
color: red;
6+
display: -webkit-box;
7+
display: -webkit-flex;
8+
display: -ms-flexbox;
9+
display: flex;
610
background-color: orange;
711
}
812
/* app.css */

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"less": "^3.10.3",
3636
"less-loader": "^5.0.0",
3737
"ora": "^4.0.3",
38-
"postcss-loader": "^3.0.0",
3938
"rimraf": "^3.0.0",
4039
"sass": "^1.23.7",
4140
"sass-loader": "^8.0.0",
@@ -44,6 +43,7 @@
4443
"webpack-dashboard": "^3.2.0"
4544
},
4645
"devDependencies": {
46+
"autoprefixer": "^9.7.2",
4747
"commitizen": "^4.0.3",
4848
"commitlint": "^8.2.0",
4949
"conventional-changelog-cli": "^2.0.28",
@@ -52,6 +52,7 @@
5252
"html-webpack-plugin": "^3.2.0",
5353
"husky": "^3.1.0",
5454
"mini-css-extract-plugin": "^0.8.0",
55+
"postcss-loader": "^3.0.0",
5556
"postcss-px-to-viewport": "^1.1.1",
5657
"vue-cli-plugin-commitlint": "^1.0.4",
5758
"webpack-chain": "^6.0.0",

postcss.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
module.exports = {
22
plugins: {
3+
autoprefixer: {
4+
overrideBrowserslist: [
5+
'> 1%',
6+
'last 3 versions',
7+
'iOS >= 8',
8+
'Android >= 4',
9+
'Chrome >= 40'
10+
]
11+
},
312
'postcss-px-to-viewport': {
413
unitToConvert: 'px',
514
viewportWidth: 750,

src/style/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
width: 200px;
44
height: 200px;
55
color: red;
6+
display: flex;
67
background-color: orange;
78
}

0 commit comments

Comments
 (0)