-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior of the LoaderOptionsPlugin #2684
Comments
This behavior is intended. Loaders should not access the webpack options (all passed options should be explicit). The plan (for webpack 3) is to remove the default The sass-loader accesses As workaround you can still pass |
The css-loader accesses I think a loader needs access to the |
@jhnns I just faced this issue and need to add |
@MoOx I think you meant new webpack.LoaderOptionsPlugin({
options: {
postcss: () => options.postcssPlugins,
context: __dirname,
},
}), That fixed our problems at work. |
We should still allow to read from the webpack config to allow sane defaults. But I agree that it is good practice to make it overwritable. |
@sokra @jhnns - Need help! For sass-loader in webpack V1 i had used the following code in the configuration. This was working as desired and the theme was reflected. Now for webpack V2 I understand that we are not allowed to give it this way. So I have Somehow everything compiles fine but the variable values marked in config.scss do not change the theme. Appreciate your help. Cheers |
You should apply it this way: new webpack.LoaderOptionsPlugin({
test: /\.scss$/,
minimize: false,
debug: false,
options: {
postcss: [ autoprefixer({ browsers: ['last 5 versions'] })],
sassLoader: {
data: '@import "theme/_config.scss";',
includePaths: [resolve(__dirname, './src/client')]
}
}
}) |
@jhnns - Firstly thanks for listening to my concern. I will just share my setup so that I am clear. Boilerplate with Webpack V2, React-hot-loader V3, React-Router V4, React-toolbox (this has theming capabilities as given in their website react-toolbox.com), Webpack-dev-middleware and webpack-hot-middleware. With Webpack V1 and Webpack-Dev-server, hot reloading on. Themeing was working fine but with browser refresh. With Webpack V2 and the boilerplate mentioned above, using the above code did not pick the changes marked in the theme variable scss file. Even on browser refresh somehow the default configuration was loading with the output bundle file. So I am not confident but I think this is not working. Autoprefixer is working for sure but the sassLoader is not possibly. I have solved my problem with a hack using npm scripts to actually overwrite the node_modules global file thus giving me exactly what I need but yeah it certainly is and feels a hack :). |
Could you create a simple repo that demonstrates your problem? React has nothing to do with it. Just try to compile a simple scss file this way and then you'll see if the options are working as expected. |
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 entireoptions
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.
Used loaders:
LoaderOptionsPlugin config:
Loader versions:
- **Browser:** all - **Language:** all
The text was updated successfully, but these errors were encountered: