bensampaio
bensampaio

Reputation: 3372

How to access the webpack config with the new Loader API?

My loader (external-svg-sprite-loader) requires access to the option output.publicPath defined in the webpack configuration file. According to webpack 2 documentation the this.options property in the Loader API was deprecated, which means at some point my loader will no longer work. Is there another way of accessing this value or of generating a URL based on the value of output.publicPath?

Upvotes: 1

Views: 422

Answers (2)

bensampaio
bensampaio

Reputation: 3372

The solution was to use the compile time variable __webpack_public_path__.

Upvotes: 0

mbow
mbow

Reputation: 147

The webpack2 docs talk about using the LoaderOptionsPlugin to pass options to your loader context. So in this case, for options.output.publicPath one could add this to their webpack plugins config:

new webpack.LoaderOptionsPlugin({
  test: /\.svg$/,
  options: {
    output: {
      publicPath: options.publicPath,
    },
  },
}));

see also what's new in webpack2

Upvotes: 1

Related Questions