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 🙏

© 2024 – Pkg Stats / Ryan Hefner

extract-text-webpack-plugin-fixcache

v2.1.1

Published

Extract text from bundle into a file.

Downloads

4

Readme

npm node deps tests coverage chat

# for webpack 2
npm install --save-dev extract-text-webpack-plugin
# for webpack 1
npm install --save-dev [email protected]

:warning: For webpack v1, see the README in the webpack-1 branch.

const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("styles.css"),
  ]
}

It moves all the require("style.css")s in entry chunks into a separate single CSS file. So your styles are no longer inlined into the JS bundle, but separate in a CSS bundle file (styles.css). If your total stylesheet volume is big, it will be faster because the CSS bundle is loaded in parallel to the JS bundle.

|Advantages|Caveats| |:---------|:------| | Fewer style tags (older IE has a limit) | Additional HTTP request | | CSS SourceMap (with devtool: "source-map" and extract-text-webpack-plugin?sourceMap) | Longer compilation time | | CSS requested in parallel | No runtime public path modification | | CSS cached separate | No Hot Module Replacement | | Faster runtime (less code and DOM operations) | ... |

new ExtractTextPlugin(options: filename | object)

|Name|Type|Description| |:--:|:--:|:----------| |id|{String}|Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)| |filename|{String\|Function}|Name of the result file. May contain [name], [id] and [contenthash]| |allChunks|{Boolean}|Extract from all additional chunks too (by default it extracts only from the initial chunk(s))| |disable|{Boolean}|Disables the plugin| |ignoreOrder|{Boolean}|Disables order check (useful for CSS Modules!), false by default|

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

:warning: ExtractTextPlugin generates a file per entry, so you must use [name], [id] or [contenthash] when using multiple entries.

#extract

ExtractTextPlugin.extract(options: loader | object)

Creates an extracting loader from an existing loader. Supports loaders of type { loader: [name]-loader -> {String}, options: {} -> {Object} }.

|Name|Type|Description| |:--:|:--:|:----------| |options.use|{String}/{Array}/{Object}|Loader(s) that should be used for converting the resource to a CSS exporting module (required)| |options.fallback|{String}/{Array}/{Object}|loader(e.g 'style-loader') that should be used when the CSS is not extracted (i.e. in an additional chunk when allChunks: false)| |options.publicPath|{String}|Override the publicPath setting for this loader|

Multiple Instances

There is also an extract function on the instance. You should use this if you have more than one instance of ExtractTextPlugin.

const ExtractTextPlugin = require('extract-text-webpack-plugin');

// Create multiple instances
const extractCSS = new ExtractTextPlugin('stylesheets/[name]-one.css');
const extractLESS = new ExtractTextPlugin('stylesheets/[name]-two.css');

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: extractCSS.extract([ 'css-loader', 'postcss-loader' ])
      },
      {
        test: /\.less$/i,
        use: extractLESS.extract([ 'css-loader', 'less-loader' ])
      },
    ]
  },
  plugins: [
    extractCSS,
    extractLESS
  ]
};

Extracting Sass or LESS

The configuration is the same, switch out sass-loader for less-loader when necessary.

const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          //resolve-url-loader may be chained before sass-loader if necessary
          use: ['css-loader', 'sass-loader']
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('style.css')
    //if you want to pass in options, you can do so:
    //new ExtractTextPlugin({
    //  filename: 'style.css'
    //})
  ]
}

Modify filename

filename parameter could be Function. It passes getPath to process the format like css/[name].css and returns the real file name, css/js/a.css. You can replace css/js with css then you will get the new path css/a.css.

entry: {
  'js/a': "./a"
},
plugins: [
  new ExtractTextPlugin({
    filename:  (getPath) => {
      return getPath('css/[name].css').replace('css/js', 'css');
    },
    allChunks: true
  })
]