The loader chapter of Webpack Advanced

Source: Internet
Author: User
Tags postcss

Webpack's loaders is a major feature and an important part of it. This blog I will be classified to explain some of the commonly used Laoder

First, the pretreatment of loaders
    • Css-loader handling issues such as path references in CSS

    • Style-loader dynamically writing styles to CSS

    • Sass-loader Scss Compiler

    • Less-loader less compiler

    • Postcss-loader Scss re-processing

npm install --save -dev css-loader style-loader sass-loader less-loader postcss-loader

Chestnuts:

module: {  loaders: [    {test: /\.css$/, loader: "style!css?sourceMap!postcss"},    {test: /\.less$/, loader: "style!css!less|postcss"}, {test: /\.scss$/, loader: "style!css!sass|postcss"} ]}
Second, loaders's JS processing
    • Babel-loader

    • Jsx-loader

npm install --save-dev babel-core babel-preset-es2015 babel-loader jsx-loader

Chestnuts

Create a new .babelrc file with a name

{  "presets": ["es2015","react"],  "plugins":["antd"]}

Create a new name for the webpack.config.js file

 module.exports ={ entry:  './entry.js ',  output: {path: __dirname, filename:  ' bundle.js '}, module: {loaders: [{test: /\.js$/, loader:  "Babel", exclude: /node_modules/}, {test: /\.jsx$/, loader:  "Jsx-loader"} {test: /.css$/, loader:  ' Style!css '}]}};         
Third, the picture processing of loaders
    • Url-loader

npm install --save-dev url-loadr

module: {  loaders: [    {test: /\.(jpg|png)$/, loader: "url?limit=8192"},  ]}
Iv. document processing of loaders
    • File-loader

npm install --save-dev file-loader

module: {  loaders: [    {      test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/, loader: ‘file‘ }, ]}
V. Loaders's JSON processing
    • Json-loader

npm install --save-dev json-loader

module: {  loaders: [    {test: /\.json$/,loader: ‘json‘},  ]}
Vi. HTML processing of loaders
    • Raw-loader

npm install --save-dev raw-loader

module: {  loaders: [    { test: /\.html$/,loader: ‘raw‘},  ]}

The loader chapter of Webpack Advanced

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.