npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@easy-webpack/config-css

v4.0.2

Published

Easy Webpack configuration function for CSS

Downloads

502

Readme

@easy-webpack/config-css

Include and inject css using css-loader and style-loader

Or emit a CSS file of all required css using extract-text-plugin (default behaviour)

Installation

npm install --save-dev @easy-webpack/config-css

easy-webpack is also required.

Usage

// webpack.config.js
const generateConfig = require('@easy-webpack/core').generateConfig;

const baseConfig = { ... }; // project-specific config like the entry file

module.exports = generateConfig(
  baseConfig,

  require('@easy-webpack/config-css')
    ({/* Options object */ filename: 'styles.css', allChunks: true, sourceMap: false })
);

// This config will generate a CSS file named 'style.css' on output path of all required sources

On any JavaScript module, simply import your css file and they will be included in output css.

// app.js
require('./style.css')  // CommonJS style import
import './style.css'    // ES Module import

Remember to include the css file in your HTML.

Options

extractText

Type: boolean | ExtractTextPlugin instance | ExtractTextPlugin config object Default: true

Toggle mode of this plugin. If this is false, inline mode will be used. No additional CSS file will be generated and all imported css modules will be injected by style-loader.

Unless you have special needs, it is not recommended to turn on inline mode because of performance issue.

You can configure the behaviour of extract-text-plugin by passing options of it using any of the following methods.

const generateConfig = require('@easy-webpack/core').generateConfig;

// Pass in ExtractTextPlugin instance
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var extractText = new ExtractTextPlugin({
  disable: false,
    allChunks: false,
    id: 'my-unique-id'
}); 

// Pass in plain config object
var extractText = {
  disable: false,
  allChunks: false,
  id: 'my-unique-id'
};

generateConfig(
  require('@easy-webpack/config-css')
    ({ extractText: extractText })
)

Note: other options will have a higher priority on overriding extract text plugin options. For example, if extractText.allChunks is false while allChunks on config-css options is true, the result would be true.

filename

Type: string Default: [name].css

Filename of the extracted css file. Similar to webpack's output filename, a dynamic name can be used. The following string will be substituted.

  • [name] the name of the chunk
  • [id] the number of the chunk
  • [contenthash] a hash of the content of the extracted file

allChunks

Type: boolean Default: false

By default, extract-text-plugin only extract initial chunk(s). If this is true, additional chunks will also be extracted.

sourceMap

Type: boolean Default: false

If true, emit a sourcemap of the CSS bundle.

resolveRelativeUrl

Type: boolean | resolve-url-loader config object Default: false

If not false, use resolve-url-loader to resolve relative url before css-loader issue require request.

This option can be an plain object containing options for resolve-url-loader.

If resolve-url-loader is turned on, sourceMap will be set to true as the plugin requires source map to function.

additionalLoaders

Type: string[] Default: []

Additional loaders.

This array of loaders will be pushed to the end of loader list. For instance,

(Take inline mode loader chain as example,)
style-loader!css-loader!additional-loaders1!additional-loaders2

test

Type: Webpack Condition Default: /\.css$/i

Condition for this config to apply. See webpack module condition guide.

Related tutorials

Tips

Minify CSS

css-loader have built in minification facility using cssnano.

Minification is highly recommended in production as it can greatly reduce chunk size and give better performance on loading.

To enable minification, you must enable minification flag on webpack.

For webpack 1, include uglifyJS plugin.

For webpack 2, include uglifyJS plugin or include a loader-options-plugin.

Or just include config-uglify.

Note on using loader-options-plugin: You may only use this plugin once with a given test, as it will override all the options once used and can cause problems

const webpack = require('webpack');
const generateConfig = require('@easy-webpack/core').generateConfig;
// webpack 1 / webpack 2
generateConfig(
  require('@easy-webpack/config-css')(),
  {
    plugins: [new webpack.optimize.UglifyJsPlugin()]
  }
);

// webpack 2 only
generateConfig(
  require('@easy-webpack/config-css')(),
  {
    plugins: [new webpack.LoaderOptionsPlugin({
      test: /\.css$/,
      minimize: true
    })]
  }
);

// config-uglify
generateConfig(
  require('@easy-webpack/config-css')(),
  require('@easy-webpack/config-uglify')()
);

Currently, there is no way to pass in option to cssnano.