Skip to content

Prevent caching CSS when in development mode #34

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

Closed
wants to merge 1 commit into from
Closed

Prevent caching CSS when in development mode #34

wants to merge 1 commit into from

Conversation

pronebird
Copy link

Fixes issue #33

@michalkvasnicak
Copy link
Owner

I think there should be change in writing logic, because now it is appending to css file. So it should do something like this.

if devMode is enabled, it should completely rewrite css file, otherwise it should append.

@michalkvasnicak
Copy link
Owner

And there is another thing to solve, we have to send all css contents to writeCss function because now it accepts only current transpiled css file and not all the previous css files.

@pronebird
Copy link
Author

pronebird commented Feb 8, 2017

I am testing with single CSS file and combined CSS is always being overwritten.

Ah that's because of https://github.com/michalkvasnicak/babel-plugin-css-modules-transform/blob/master/src/utils/extractCssFile.js#L33

@michalkvasnicak
Copy link
Owner

It is overwriting file if there is only 1 css file otherwise it is appending and this causes tests to fail.

@pronebird
Copy link
Author

I see, you're right. Let me see what I can do about it.

@pronebird
Copy link
Author

pronebird commented Feb 8, 2017

If I run babel --watch --skip-initial-build it does not process files therefore changes to single file pretty much result in overwrite of entire CSS with the rules of changed CSS file.

I skip initial build because there is no way to know when babel --watch finishes generating file structure. Therefore I run babel twice, first time to generate file structure, after that I run electron app + babel --watch simultaneously.

It's possible to run babel without --skip-initial-build to let it pass all files once again, it's redundant but then transpiler would get enough information about all CSS files then. Other option is to generate CSS files in separate folder structure and import all of them within single stylesheet.css which I can manually create or write script to produce.

@michalkvasnicak
Copy link
Owner

michalkvasnicak commented Feb 8, 2017

I think that we could solve regeneration of whole combined css file.

We could always rewrite whole combined css file but I am not sure what impact it'll have on performance of plugin. Maybe we can do checks in cache not only by filename but hash of contents for example? Then we'll know if we need to overwrite the whole combined css file or just keep it as is because contents haven't changed.

@michalkvasnicak
Copy link
Owner

So in non devMode we'll keep the old logic and in devMode we will check contents too and rewrite css only if the css content is new or changed.

@pronebird
Copy link
Author

pronebird commented Feb 8, 2017

Another option would be to always append in dev-mode but mark each entry in combined CSS somehow so we could strip out old rules before appending new ones.

Performance wise this would be much faster then looping through all styles and generating combined CSS. This should also address my case with --skip-initial-build.

I mean all of it is not ideal right?

@michalkvasnicak
Copy link
Owner

Yeah but you'll end up with rewriting file anyway because if the string you want to strip is in the middle of the combined CSS file you don't have a way to strip it.

So maybe something like, if the file is new append otherwise strip and rewrite. And we could keep the generated CSS in memory too.

@michalkvasnicak
Copy link
Owner

Closing, you can try next version (#38).

@pronebird pronebird deleted the fix/prevent-devmode-caching branch March 11, 2017 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants