Home  >  Article  >  Web Front-end  >  Configuration methods of webpack's scss and postcss-loader

Configuration methods of webpack's scss and postcss-loader

小云云
小云云Original
2018-01-11 09:24:361730browse

This article mainly introduces the detailed configuration of scss and postcss-loader in webpack. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

Start


##

npm i sass-loader node-sass postcss-loader autoprefixer

First configure postcss-loader

Here postcss is In order to add a private prefix to the browser kernel. Currently postcss has other operations such as px2rem. You can think of postcss as babel-core is just a control center, the main thing is its scattered plug-ins.


/**** package.json ****/
// 指定你的前缀的兼容版本。
// 目前指定的只添加-webkit-, -ms-
// 你也可以兼容更低或者更高的的浏览器来增加或减少内核前缀的数量。
"browserslist": [
  "> 1%",
  "last 2 versions",
  "not ie <= 8"
]
/**** .postcssrc.js ****/
// 增加一个.postcssrc.js来指定postcss所使用的插件。就跟.babelrc类似
module.exports = {
 plugins:{
  "autoprefixer": {}
 }
}
/**** build.js生产环境 ****/
{
   test: /\.css$/,
   use: ExtractTextWebpackPlugin.extract({
   fallback: &#39;style-loader&#39;,
-    use: &#39;css-loader&#39;
+    use: [&#39;css-loader&#39;, &#39;postcss-loader&#39;, &#39;sass-loader&#39;]
   })
 }
/**** dev.js开发环境 ****/
// 其实个人认为在开发环境可加可不加
{
   test: /\.css$/,
   use: [&#39;style-loader&#39;, &#39;css-loader&#39;, &#39;postcss-loader&#39;]
},

scss configuration

is nothing more than adding rules


/**** build.js ****/
{
  test: /\.scss$/,
  use: ExtractTextWebpackPlugin.extract({
   fallback: &#39;style-loader&#39;,
   use: [&#39;css-loader&#39;, &#39;postcss-loader&#39;, &#39;sass-loader&#39;]
  })
}
/**** dev.js ****/
{
  test: /\.scss$/,
  use: [&#39;style-loader&#39;, &#39;css-loader&#39;, &#39;postcss-loader&#39;, &#39;sass-loader&#39;]
}

Related recommendations:

Detailed explanation of the method of supporting SCSS in Angular

The implementation of SCSS mobile page mask layer effect and solutions to common problems

CSS and Sass (SCSS) development specifications

The above is the detailed content of Configuration methods of webpack's scss and postcss-loader. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn