Skip to content

Commit

Permalink
feat(compiler-postcss): add postcss compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
fsy0718 authored and Gcaufy committed Oct 3, 2018
1 parent e291948 commit 0d6b49b
Show file tree
Hide file tree
Showing 11 changed files with 1,638 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/compiler-postcss/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# wepy postcss 编译器

## 安装

```
npm install wepy-compiler-postcss --save-dev
```


## 配置 `wepy.config.js` ,以使用 `cssnext` 为例

```
const cssnext = require('cssnext);
module.exports = {
"compilers": {
postcss: {
plugins: [
cssnext({
browsers:['iOS 9', 'Android 4.4']
})
],
map: {
inline: true
}
},
}
};
```

## 参数说明
配置参数为[processOptions](http://api.postcss.org/global.html#processOptions)[plugins](http://api.postcss.org/global.html#Plugin)


## 已知Bug

使用`cssnano`插件压缩css时,由于其依赖`macaddress`存在全局变量泄露问题,将导致无法完成编译过程。
问题相关:[Github](https://github.com/webpack-contrib/css-loader/pull/472)

## Contributor

[fsy0718](mailto:[email protected])
18 changes: 18 additions & 0 deletions packages/compiler-postcss/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const postcss = require('postcss')

exports = module.exports = function (options = {}) {
const {plugins = [], ...other} = options
return function () {
this.register('wepy-compiler-postcss', function (node, file) {
return postcss(plugins).process(node.content || '', {
from: file,
...other
}).then(res => {
node.compiled = {
code: res.css
}
return node
})
})
}
}
Loading

0 comments on commit 0d6b49b

Please sign in to comment.