W3cubDocs

/webpack 2

LoaderOptionsPlugin

Review this content

The LoaderOptionsPlugin is unlike other plugins. It exists to help people move from webpack 1 to webpack 2. With webpack 2 the schema for a webpack.config.js became stricter; no longer open for extension by other loaders / plugins. With webpack 2 the intention is that you pass options directly to loaders / plugins. i.e. options are not global / shared.

However, until a loader has been updated to depend upon options being passed directly to them, the LoaderOptionsPlugin exists to bridge the gap. You can configure global / shared loader options with this plugin and all loaders will receive these options.

In the future this plugin may be removed.

new webpack.LoaderOptionsPlugin(options)
  • options.debug (boolean): Whether loaders should be in debug mode or not. debug will be removed as of webpack 3.
  • options.minimize (boolean): Where loaders can be switched to minimize mode.
  • options.options (object): A configuration object that can be used to configure older loaders - this will take the same schema a webpack.config.js

  • options.options.context (string): The context that can be used to configure older loaders

  • other options as in a webpack.config.js....

Examples

new webpack.LoaderOptionsPlugin({
  minimize: true,
  debug: false,
  options: {
    context: __dirname
  }
})

© 2012–2016 Tobias Koppers
Licensed under the Creative Commons Attribution License 4.0.
https://webpack.js.org/plugins/loader-options-plugin/