Details about the configuration of webpack scss and postcss-loader, webpackscss

Source: Internet
Author: User
Tags postcss

Details about the configuration of webpack scss and postcss-loader, webpackscss

This article describes the configuration of scss and postcss-loader for webpack. The details are as follows:

Start

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

First configure postcss-loader

Postcss is used to add a private prefix to the browser kernel. Currently, postcss has other operations such as px2rem. Postcss can be imagined as babel-core, which is only a control center and mainly a plug-in that is scattered out of it.

/***** Package. json ***** // specify the compatible version of your prefix. // Currently, only the specified-webkit-and-ms-are added. // You can also add or reduce the number of kernel prefixes in a browser with lower or higher compatibility. "Browserslist": ["> 1%", "last 2 versions", "not ie <= 8"]/*****. postcssrc. js *** // Add one. postcssrc. js to specify the plug-in used by postcss. Just like. babelrc is similar to module. exports = {plugins: {"autoprefixer": {}}/ ***** build. js production environment ***/{test :/\. css $/, use: ExtractTextWebpackPlugin. extract ({fallback: 'style-loader ',-use: 'css-loader' + use: ['css-loader ', 'postcss-loader ', 'sass-loader ']})}/***** dev. js Development Environment ***** // in fact, I personally think that {test:/\ can be added in the development environment :/\. css $/, use: ['style-loader ', 'css-loader', 'postcss-loader ']},

Scss Configuration

Add 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']}

Github

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.