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: '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'] }
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!