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: 'style-loader', - use: 'css-loader' + use: ['css-loader', 'postcss-loader', 'sass-loader'] }) } /**** dev.js开发环境 ****/ // 其实个人认为在开发环境可加可不加 { test: /\.css$/, use: ['style-loader', 'css-loader', 'postcss-loader'] },
scss configuration
is nothing more than adding rules
/**** build.js ****/ { test: /\.scss$/, use: ExtractTextWebpackPlugin.extract({ fallback: 'style-loader', use: ['css-loader', 'postcss-loader', 'sass-loader'] }) } /**** dev.js ****/ { test: /\.scss$/, use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'] }
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!