Skip to content

Prevent output file content changes between compiles #101

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

Merged
merged 1 commit into from
Jun 13, 2017

Conversation

andris-silis
Copy link
Contributor

When this plugin is used, output content is changed between compiles as it uses random number in output when import is used without assign to variable (import "./style.css";). This causes output file hash changes between builds having equal input and long-term asset caching for web is not working.

My guess the random is used to identify imports so I replaced random with style file name and it's location in source to prevent clashes when the same file is imported multiple times (not sure if such case exists though).

Let me know if this is ok, I'm gonna adjust code style to your needs and add tests.
I guess the process.env.NODE_ENV === 'test' conditional and it's contents can be removed as well as styleImportName won't change anymore between tests?

@gajus
Copy link
Owner

gajus commented Jun 13, 2017

huh, using Math.random() was shortsighted of me.

Thank you for the PR. Ping me when it is ready to merge.

@gajus gajus self-requested a review June 13, 2017 10:01
@andris-silis andris-silis force-pushed the non-random-style-name branch from d0048a9 to b435517 Compare June 13, 2017 11:48
@andris-silis
Copy link
Contributor Author

@gajus Done. I removed the line/column part as a single "anonymous" import is allowed anyway and there should not be name clashes in style map.

@gajus gajus merged commit ab2fe0e into gajus:master Jun 13, 2017
@gajus
Copy link
Owner

gajus commented Jun 13, 2017

Thank you

NE-SmallTown added a commit to NE-SmallTown/babel-plugin-react-css-modules that referenced this pull request Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants