-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Hotloading imported css styles #8
Comments
Sorry, but I am not webpack user anymore, so I have no skills to fix hotloading. @0nn0 maybe you can ask somebody in webpack team? |
Hi @gaearon, do you by any chance have an idea how solve solve this problem? I've checked other repo's like react-hot-postcss-boilerplate, but haven't found one that has this workflow with webpack, postcss and react hotloader working... |
I checked it out but I can't figure out what exactly Does it make a real difference, or is it an optimization? Do you need it enabled in development? |
@0nn0 I think |
I think the problem is that Webpack is ignorant of PostCSS dependencies. Generally loaders should tell Webpack what files the processed file depends on, so that when dependant files change, the parent is recompiled. I don't know if PostCSS exposes the dependency tree after compiling a file. If not, there's no way to make |
Maybe we can ask |
Agreed, this seems like overcomplication. |
I will add some notice about |
Don't do that. postcss-import can already handle this. Like said in the description or the linked issue, cssnext-loader already handle this using postcss-import onImport option. |
@gaearon BTW, why webpack uses so bad parser in For example, PostCSS parser has a safe mode to load legacy CSS with any mistakes. Also PostCSS parser is one of the fastest JS parsers. There are only CSSOm faster that PostCSS, but only because it has mistakes in parsing. |
This has already been mentioned here webpack-contrib/css-loader#36 @ai I don't really know what they should put in onImport, probably something like this https://github.com/cssnext/cssnext-loader/blob/c7b79f5281a5e63adca933fc4ec434f965e686e3/index.js#L25-L27 and chaging |
Without the use of the postcss-import plugin the reloading does work, however then the PostCSS plugins get applied solely to the main stylesheet (styles.css) but to none of the css files that get imported in there (component.css). You can see that in the |
Indeed. And you cannot use postcss after css-loader since this one return js code. So this must be handled when calling postcss-loader. |
Released in 0.5 |
Seems like you forgot to publish new version to npm. |
@faergeek oops :) fixed |
Did anyone test that this worked? I don't think it's working for me. |
@matthewmueller do you use postcss-import? Do you add hook for it from docs? |
yep following the docs correction: it works, sort of. if there's no syntax errors, it will reload. if there's a syntax error, it stops compiling and you have to restart the webpack server. |
Open a new issue with all output and plugin list |
I'm having a bit of trouble getting webpack to watch the imported css files. They're being processed on the first run, but webpack does not recompile when I modify these files. I have a colors.css with some vars (w/ postcss-simple-vars) that I want to import in my other css files to use the $vars. Like in a SCSS project. So I set up my webpack config with postcss and postcss-import and everything is working as expected, except for the file watch on my color.css. Here is my postcss config: config.postcss = function(webp) {
let cssnanoOpt = {
discardUnused: false,
zindex: false
};
let rucksackOpt = { autoprefixer: true };
let devPlugins = [
postcssImport({ addDependencyTo: webp }),
mixins,
nested,
simpleVars,
rucksack(rucksackOpt),
cssnext
];
let prodPlugins = [cssnano(cssnanoOpt)];
let plugins;
if (BUILD) {
plugins = devPlugins;
} else {
plugins = devPlugins.concat(prodPlugins);
}
return plugins;
}; Any hints on what I'm doing wrong? |
Do you use style-loader?
|
Yes, with extract-text-webpack-plugin. But I disable the extract-text plugin in development for hot loading. const cssLoader = {
test: /\.css$/,
// Reference: https://github.com/webpack/extract-text-webpack-plugin
// Extract css files in production builds
//
// Reference: https://github.com/webpack/style-loader
// Use style-loader in development for hot-loading
loader: ExtractTextPlugin.extract('style', 'css?sourceMap!postcss'),
}; |
Can you show how you disable the ExtractTextPlugin ? |
I've set up a repo where you can reproduce this behavior: https://github.com/luisfontes/webpack-postcss-import-hotload Just |
@luisfontes I had also issues and I realized that it only works if this line
In my case I use cssnext and autoprefixer and the postcssImport need to be the first entry! |
Reminders:
|
@MoOx @luisfontes |
For those new to Webpack and coming to this thread and going "wah?!?" the exact code is: //webpack.config.js
var postcssImport = require('postcss-import');
...
postcss: function(webpack) {
return [
postcssImport({ addDependencyTo: webpack }), // Must be first item in list
precss,
autoprefixer
];
}, Hopefully precss will support this soon, so we won't need to use the postcss-import plugin as well. |
+6 months and precss still does not support this. Ridiculous 😠 |
Use |
@mummybot It does not work for me, I'm using webpack@2.1.0-beta.21 and postcss-import@8.1.0, does this matter? |
@ai Thanks, maybe I have to wait. |
At the moment it seems that the post-css loader combined with ReactHotLoader and the postcss-import plugin does not auto-reload any stylesheets that get imported in a main css file.
I've created an example case in the following repo:
https://github.com/0nn0/hotloader-postcss-imports/tree/postcss-import-plugin
You can produce the problem using the following steps.
postcss-import-plugin
Is there a way that this can be solved?
@MoOx offered a suggestion here that the postcss-loader perhaps can make use of onImport like here if postcss-import is detected?
postcss/postcss-import#40
The text was updated successfully, but these errors were encountered: