Skip to content

Webpack plugin to separate css files based on media queries.

Notifications You must be signed in to change notification settings

wettercom/css-mq-splitter-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CSS Media Query splitter plugin for webpack

Usage example

If you have the following CSS:

.test {
  color: red;
}

@media screen and (min-width: 720px) {
  .test {
    color: blue;
    font-size: 2em;
  }
}

@media screen and (min-width: 720px) {
  .test2 {
    background: blue;
  }
}

@media screen and (min-width: 1200px) {
  .test {
    color: green;
    font-size: 3em;
  }
}

And you configure your webpack to use this plugin:

var CSSMQSplitterPlugin = require("css-mq-splitter-plugin");
module.exports = {
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract("style", "css")
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("bundle.css"),
    new CSSMQSplitterPlugin({
      "screen and (min-width: 720px)": 'tablet',
      "screen and (min-width: 1200px)": 'desktop'
    })
  ]
}

This configuration will create the following files

  • bundle.css
  • bundle.tablet.css
  • bundle.desktop.css

You can then use the following following files to be included in your html like so:

<link rel="stylesheet" href="bundle.css" />
<link rel="stylesheet" media="screen and (min-width: 720px)" href="bundle.tablet.css" />
<link rel="stylesheet" media="screen and (min-width: 1200px)": 'desktop" href="bundle.desktop.css" />

About

Webpack plugin to separate css files based on media queries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%