split-css-loader

0.1.0 • Public • Published

split-css-loader Build Status

split-css-loader is a webpack loader that allows conditional compilation of CSS via media queries. For example, you can have split styling for a "desktop" and "xbox" build:

body {
    background-color: #000;
    color: #fff;
}
 
@media (platform: desktop) {
    div:before {
        content: "This is the desktop build!";
    }
}
 
@media (platform: xbox) {
    div:before {
        content: "This is the XBOX build!";
    }
}
 
@media (platform: not-xbox) {
    div:after {
        content: "This is not the XBOX build!";
    }
}

Usage

Your webpack.config.js might look something like this:

module.exports = {
  // ...
  module: {
    preLoaders: [
      { test: /\.css$/, loader: 'split-css?target=platform&value=xbox' },
    ],
    loaders: [
      { test: /\.css$/, loader: 'style!css' },
    ]
  }
};

The loader takes two parameters, the target specifying the media query key you want to compile against, and the value you want that key to be. In this case, we specified that we only want to compiled @media (platform: xbox) and want everything else to be stripped out.

Programmatic API

You can also use this module natively, in Node. The options are the same, you simply pass in a CSS string you want to parse:

const split = require('split-css-loader');
 
fs.writeFileSync('./style.css', split.string(myStyle, {
  target: 'platform',
  value: 'xbox'
}));

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    0

Package Sidebar

Install

npm i split-css-loader

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mcph