Skip to content

Unexpected behavior of the LoaderOptionsPlugin #2684

@kiurchv

Description

@kiurchv

I'm submitting a bug report

Webpack version:
2.x

Please tell us about your environment:
OSX 10.x

Current behavior:
I'm using LoaderOptionsPlugin to pass options to postcss-loader. When using the plugin, other loaders in the chain unable to access the webpack options object and failing with TypeError: Cannot read property 'path' of undefined at Object.module.exports ([project path]/node_modules/sass-loader/index.js:227:52). It seems that this plugin overriding entire options property in the loader context with the given values.

Expected/desired behavior:
LoaderOptionsPlugin should extend webpack options in the loader context with the given options instead of overriding entire object and making webpack options unaccessible for loaders.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.

Used loaders:

{
  test: /\.scss$/i,
  loaders: [
    "style-loader",
    {
      loader: "css-loader",
      query: {
        sourceMap: true,
        modules: true,
        importLoaders: 2
      }
    },
    {
      loader: "sass-loader",
      query: {
        sourceMap: true,
      }
    },
    {
      loader: "postcss-loader"
    }
  ]
}

LoaderOptionsPlugin config:

new webpack.LoaderOptionsPlugin({
  test: /\.scss$/i,
  options: {
    postcss: {
      plugins: [autoprefixer, postcssReporter({ clearMessages: true })],
      syntax: scssSyntax
    }
  }
});

Loader versions:

  • style-loader: 0.13.1
  • css-loader: 0.23.1
  • sass-loader: 3.2.0
  • postcss-loader: 0.9.1

- **Browser:** all - **Language:** all

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions