All Projects → webpack-contrib → Extract Text Webpack Plugin

webpack-contrib / Extract Text Webpack Plugin

Licence: mit
[DEPRECATED] Please use https://github.com/webpack-contrib/mini-css-extract-plugin Extracts text from a bundle into a separate file

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to Extract Text Webpack Plugin

webpack-auto-inject-version
Webpack plugin to auto inject version into html or file
Stars: ✭ 70 (-98.28%)
Mutual labels:  webpack-plugin
Webpack Sentry Plugin
Webpack plugin to upload source maps to Sentry
Stars: ✭ 299 (-92.66%)
Mutual labels:  webpack-plugin
Webpack Extension Reloader
A upgrade from 🔥webpack-chrome-extension-reloader🔥, now on all browsers
Stars: ✭ 355 (-91.28%)
Mutual labels:  webpack-plugin
ignore-emit-webpack-plugin
Prevents ignored files from being emitted during a Webpack build
Stars: ✭ 17 (-99.58%)
Mutual labels:  webpack-plugin
Webpack Virtual Modules
Webpack Virtual Modules is a webpack plugin that lets you create, modify, and delete in-memory files in a way that webpack treats them as if they were physically presented in the file system.
Stars: ✭ 286 (-92.97%)
Mutual labels:  webpack-plugin
Filemanager Webpack Plugin
Copy, move, archive (zip/tar/tar.gz), delete files and directories before and after Webpack builds. Win32/Mac/*Nix supported
Stars: ✭ 310 (-92.39%)
Mutual labels:  webpack-plugin
copy-modules-webpack-plugin
A Webpack plugin which copies module sources to a separate directory
Stars: ✭ 17 (-99.58%)
Mutual labels:  webpack-plugin
Webpack Chrome Extension Reloader
🔥 Hot reloading while developing Chrome extensions with webpack 🔥
Stars: ✭ 365 (-91.03%)
Mutual labels:  webpack-plugin
Purgecss Webpack Plugin
Purgecss plugin for webpack
Stars: ✭ 299 (-92.66%)
Mutual labels:  webpack-plugin
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (-91.35%)
Mutual labels:  webpack-plugin
stylos
Webpack plugin to automatically generate and inject CSS utilities to your application
Stars: ✭ 60 (-98.53%)
Mutual labels:  webpack-plugin
Webpack Assets Manifest
This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.
Stars: ✭ 269 (-93.39%)
Mutual labels:  webpack-plugin
Web Webpack Plugin
alternative for html-webpack-plugin
Stars: ✭ 318 (-92.19%)
Mutual labels:  webpack-plugin
swig-webpack-plugin
Render swig templates with webpack.
Stars: ✭ 12 (-99.71%)
Mutual labels:  webpack-plugin
Vuetify Loader
📦 A Webpack plugin for treeshaking Vuetify components and more
Stars: ✭ 356 (-91.26%)
Mutual labels:  webpack-plugin
chunk-splitting-plugin
Arbitrarily split your Webpack chunks and bundles into smaller pieces
Stars: ✭ 15 (-99.63%)
Mutual labels:  webpack-plugin
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (-92.48%)
Mutual labels:  webpack-plugin
Moment Locales Webpack Plugin
Easily remove unused Moment.js locales with webpack
Stars: ✭ 396 (-90.27%)
Mutual labels:  webpack-plugin
Browser Sync Webpack Plugin
Easily use BrowserSync in your Webpack project.
Stars: ✭ 356 (-91.26%)
Mutual labels:  webpack-plugin
I18n Webpack Plugin
[DEPRECATED] Embed localization into your bundle
Stars: ✭ 320 (-92.14%)
Mutual labels:  webpack-plugin

DEPRECATED

Please use: https://github.com/webpack-contrib/mini-css-extract-plugin

If you have problem(s) with migration on MiniCssExtractPlugin feel free to open issue with reproducible test repo, thanks


npm node deps tests coverage chat

Extract Text Plugin

Extract text from a bundle, or bundles, into a separate file.

Install

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

Usage

⚠️ Since webpack v4 the extract-text-webpack-plugin should not be used for css. Use mini-css-extract-plugin instead.

⚠️ 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 required *.css modules in entry chunks into a separate CSS file. So your styles are no longer inlined into the JS bundle, but in a separate CSS 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) ...

Options

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))
When using CommonsChunkPlugin and there are extracted chunks (from ExtractTextPlugin.extract) in the commons chunk, allChunks must be set to true
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
  • [<hashType>:contenthash:<digestType>:<length>] optionally you can configure
    • other hashTypes, e.g. sha1, md5, sha256, sha512
    • other digestTypes, e.g. hex, base26, base32, base36, base49, base52, base58, base62, base64
    • and length, the length of the hash in chars

⚠️ 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',
          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'
    //})
  ]
}

url() Resolving

If you are finding that urls are not resolving properly when you run webpack. You can expand your loader functionality with options. The url: false property allows your paths resolved without any changes.

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

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
                loader: 'css-loader',
                options: {
                    // If you are having trouble with urls not resolving add this setting.
                    // See https://github.com/webpack-contrib/css-loader#url
                    url: false,
                    minimize: true,
                    sourceMap: true
                }
            }, 
            {
                loader: 'sass-loader',
                options: {
                    sourceMap: true
                }
            }
          ]
        })
      }
    ]
  }
}

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
  })
]

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].