Giter Club home page Giter Club logo

css-split-webpack-plugin's Introduction

css-split-webpack-plugin

Split your CSS for stupid browsers using webpack and postcss.

build status coverage license version downloads

Using webpack to generate your CSS is fun for some definitions of fun. Unfortunately the fun stops when you have a large app and need IE9 support because IE9 will ignore any more than ~4000 selectors in your lovely generated CSS bundle. The solution is to split your CSS bundle smartly into multiple smaller CSS files. Now you can.™ Supports source-maps.

Installation

npm install --save css-split-webpack-plugin

Usage

Simply add an instance of CSSSplitWebpackPlugin to your list of plugins in your webpack configuration file after ExtractTextPlugin. That's it!

var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CSSSplitWebpackPlugin = require('../').default;

module.exports = {
  entry: './index.js',
  context: __dirname,
  output: {
    path: __dirname + '/dist',
    publicPath: '/foo',
    filename: 'bundle.js',
  },
  module: {
    loaders: [{
      test: /\.css$/,
      loader: ExtractTextPlugin.extract('style-loader', 'css-loader'),
    }],
  },
  plugins: [
    new ExtractTextPlugin('styles.css'),
    new CSSSplitWebpackPlugin({size: 4000}),
  ],
};

The following configuration options are available:

size: default: 4000 The maximum number of CSS rules allowed in a single file. To make things work with IE this value should be somewhere around 4000.

imports: default: false If you originally built your app to only ever consider using one CSS file then this flag is for you. It creates an additional CSS file that imports all of the split files. You pass true to turn this feature on, or a string with the name you'd like the generated file to have.

filename: default: "[name]-[part].[ext]" Control how the split files have their names generated. The default uses the parent's filename and extension, but adds in the part number.

preserve: default: false. Keep the original unsplit file as well. Sometimes this is desirable if you want to target a specific browser (IE) with the split files and then serve the unsplit ones to everyone else.

defer: default: 'false'. You can pass true here to cause this plugin to split the CSS on the emit phase. Sometimes this is needed if you have other plugins that operate on the CSS also in the emit phase. Unfortunately by doing this you potentially lose chunk linking and source maps. Use only when necessary.

css-split-webpack-plugin's People

Contributors

bowlingx avatar didi0613 avatar izaakschroeder avatar jjt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css-split-webpack-plugin's Issues

Webpack 2 support - part 2

I tried the 0.2.2 and it's not working with Webpack 2.

There is another import issue : Error: Cannot find module 'webpack/lib/RawSource'
Importing RawSource from webpack-sources resolve the import error but it crashed during the webpack build : http://pastie.org/10977708

Webpack 2 support

Hello,

Is this supposed to work with webpack 2 ? I get this : Error: Cannot find module 'webpack/lib/SourceMapSource
Not sure if this is a configuration issue or a lack of webpack 2 support.

Thanks.

Options to split by rules instead of size?

There may be quite a few rules only used in certain circumstances. (eg. IE X specific rules, media queries etc.). They shouldn't be split by size but rules. Is it possible or any other ways to achieve this?

imports path incorrect when publicPath is relative

  1. imports: true
  2. publicPath: 'dist/'

The split file containing the imports is put in the right place under dist along with the pieces. However, the @import points to "dist/styles-1.css". Since these are relative to the current split file, it's looking under "dist/dist/styles-1.css".

Not a big deal on my end. I simply made my publicPath context-relative. Just thought I'd submit the issue in case others run into it.

Is it possible to get css-split-webpack-plugin working with webpack-manifest-plugin?

I am trying to set up css-split-webpack-plugin in my Rails application. It uses webpack-manifest-plugin to generate manifest.

When I compile my main.css file it gets splitted into two files:

  • main-ba361f9ac7a251e81763-1.css
  • main-ba361f9ac7a251e81763-2.css

but into the manifest is added the second file only:

cat public/packs/manifest.json
=>
...
  "main.css": "/packs/main-ba361f9ac7a251e81763-2.css",
  "main.css.map": "/packs/main-ba361f9ac7a251e81763-2.css.map",
...

Is it possible to fix this issue and include into the manifest both files? Like this:

...
  "main-1.css": "/packs/main-ba361f9ac7a251e81763-1.css",
  "main-1.css.map": "/packs/main-ba361f9ac7a251e81763-1.css.map",
  "main-2.css": "/packs/main-ba361f9ac7a251e81763-2.css",
  "main-2.css.map": "/packs/main-ba361f9ac7a251e81763-2.css.map",
...

Source maps not working with less

I load in less like so
{ test: /\.(less|css)$/, loader: ExtractTextPlugin.extract('css?-url&-autoprefixer&sourceMap!less?sourceMap') }
with plugins
new ExtractTextPlugin('[name].css'), new CSSSplitWebpackPlugin({ //IE9 will ignore any more than ~4000 selectors. This does the work for us of splitting into smaller files. imports: true, preserve: true })

Tried with and without preserve. Even with the preserved sheet, the source map won't load (testing in Chrome). Works fine when I comment out this plugin.

Webpack 4 support

Hi,

I know this is a huge change, but I've just tested using mini-css-extract-plugin instead of the extract-text-webpack-plugin, and it worked, though it had a warning on a deprecated Tapable.

Is Webpack 4 support planed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.