File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -164,6 +164,55 @@ PostCSS 可以转化样式到任意语法,不仅仅是 CSS。
164164
165165[ 选择插件 ] : http://postcss.parts
166166
167+ ### CSS-in-JS
168+
169+ 同时使用 PostCSS 与 CSS-in-JS 的最好方式是 [ ` astroturf ` ] ( https://github.com/4Catalyzer/astroturf ) ,将它的 loader 添加到 ` webpack.config.js ` 中:
170+
171+ ``` js
172+ module .exports = {
173+ module: {
174+ rules: [
175+ {
176+ test: / \. css$ / ,
177+ use: [' style-loader' , ' postcss-loader' ],
178+ },
179+ {
180+ test: / \. jsx? $ / ,
181+ use: [' babel-loader' , ' astroturf/loader' ],
182+ }
183+ ]
184+ }
185+ }
186+ ```
187+
188+ 然后创建 ` postcss.config.js ` :
189+
190+ ``` js
191+ module .exports = {
192+ plugins: [
193+ require (' autoprefixer' ),
194+ require (' postcss-nested' )
195+ ]
196+ }
197+ ```
198+
199+ ### Parcel
200+
201+ [ Parcel] ( https://parceljs.org/ ) 有内建的 PostCSS 支持,并已经使用 Autoprefixer 和 cssnano。如果你想更换插件,请在项目根目录中创建 ` postcss.config.js ` :
202+
203+ ``` js
204+ module .exports = {
205+ plugins: [
206+ require (' autoprefixer' ),
207+ require (' postcss-nested' )
208+ ]
209+ }
210+ ```
211+
212+ Parcel 甚至会自动地帮你安装这些插件。
213+
214+ > 请注意[ 第 1 版中存在的几个问题] ( https://github.com/parcel-bundler/parcel/labels/CSS%20Preprocessing ) ,第 2 版通过 [ issue #2157 ] ( https://github.com/parcel-bundler/parcel/projects/5 ) 解决了这些问题。
215+
167216### Webpack
168217
169218在 ` webpack.config.js ` 里使用 [ ` postcss-loader ` ] :
You can’t perform that action at this time.
0 commit comments