Webpack Separate CSS Package

Source: Internet
Author: User

Webpack Separate CSS PackageWord 285Read 0Reviews 0like 0Gab

Webpack all the resources as a module, css,image, JS font files are resources, can be packaged into a bundle.js file.
But sometimes you need to package the style separately into a file, then put it on the CND, and then cache it in the browser client.

This operation is very simple, just need a plug-in just fine, isextract-text-webpack-plugin

1. Installing Extract-text-webpack-plugin
npm install extract-text-webpack-plugin --save-dev
2. configuration file Add corresponding configuration

First require, please.

var ExtractTextPlugin = require("extract-text-webpack-plugin");

Plugins inside add

new ExtractTextPlugin("styles.css"),

Instance:

plugins: [ new webpack.optimize.CommonsChunkPlugin(‘common.js‘), new ExtractTextPlugin("styles.css"), ],

Modules inside the CSS to deal with the revision changed to

{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader","css-loader") },

Don't repeat it, or it won't work.

I am here as follows:

 module: { Loaders:[ {Test:/\.css$/,Loader: Extracttextplugin. Extract ("Style-loader","Css-loader") }, {Test:/\.scss$/,Loader: "Style!css!sass"}, {Test:/\.less$/,Loader: "Style!css!less"}, ] },
3. Add the required CSS in the introduction file, "example below"
require(‘../less/app.less‘); require(‘./bower_components/bootstrap-select/dist/css/bootstrap-select.min.css‘); require(‘./bower_components/fancybox/source/jquery.fancybox.css‘);

Webpack Separate CSS Package

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.