Home  >  Article  >  Web Front-end  >  Detailed introduction to the related configuration of scss in webpack

Detailed introduction to the related configuration of scss in webpack

亚连
亚连Original
2018-06-12 17:56:261991browse

This article mainly introduces the detailed configuration of scss and postcss-loader in webpack. Now I will share it with you and give you a reference.

This article introduces the detailed configuration of scss and postcss-loader in webpack and shares it with everyone. The details are as follows:

Start

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

First configure postcss-loader

Here postcss is 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;]
}

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

js implementation method of operating binary data

Use the swiper component in vue2.0 to implement carousel (detailed tutorial)

What are the specific methods of using Compass in Vue?

How to turn off the caching function of Vue computed properties? What are the specific steps?

The above is the detailed content of Detailed introduction to the related configuration of scss in webpack. 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