forked from Tencent/wepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler-postcss): add postcss compiler
- Loading branch information
Showing
11 changed files
with
1,638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.