css-customs-loader
Exposes custom properties, custom media queries and custom selectors to JavaScript
Last updated a year ago by silvenon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install css-customs-loader 
SYNC missed versions from official npm registry.

css-customs-loader

A webpack loader that exposes CSS customs to JavaScript.

Configuration

yarn add css-customs-loader postcss-loader postcss-preset-env

You need to add css-customs-loader before css-loader:

// webpack.config.js
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-customs-loader'
            // defaults
            options: {
              onlyLocals: false,
            },
          },
          'css-loader?importLoaders=1',
          'postcss-loader',
        ],
      },
    ],
  },
}

css-customs-loader detects any valid PostCSS configuration (including options passed to postcss-loader!), so let's create one. importFrom will point to a global.css file containing our customs and, for the sake of this example, we'll enable all features related to CSS customs:

// postcss.config.js
module.exports = {
  plugins: {
    'postcss-preset-env': {
      importFrom: 'src/global.css',
      features: {
        'custom-properties': true, // already enabled by default
        'custom-media-queries': true,
        'custom-selectors': true,
      },
    },
  },
}

Options

onlyLocals

This option should be enabled in situations like pre-rendering. You should combine it with onlyLocals option in css-loader v2 or css-loader/locals loader in css-loader v1. (Don't use style-loader when pre-rendering.)

Usage

See usage instructions in the main readme.

Current Tags

  • 0.4.0                                ...           latest (a year ago)

10 Versions

  • 0.4.0                                ...           a year ago
  • 0.3.0                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (5)
Dev Dependencies (11)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |