Skip to content
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

Fixup env checks #371

Merged
merged 1 commit into from
Feb 25, 2019
Merged

Conversation

Andarist
Copy link
Member

Regarding - https://twitter.com/DavidKPiano/status/1098437300550336512 😉

When performing env checks you should never reference process directly - replacing plugins are only concerned with replacing process.env.NODE_ENV lookup. Referencing process causes i.e. webpack to include a polyfill for this object.

Because of that developer-friendly warning which were meant to be removed in production bundles stayed in the bundles.

This has no dramatic effect but it allow bundlers to remove those unwanted strings in production, the UMD bundle went from 10.87 KB to 10.54 KB

In general I don't recommend storing env check result in a variable (inline check is easier for minifiers to remove), and I strongly would advise against exporting it from a file - especially given a fact that you don't flat bundle and depending on the consumer's setup it might not be possible to check this value across module-boundary.

This also provides a browser-friendly build which was actually requested originally ( #227 ) but the fix was done differently. cc @TimvdLippe

@TimvdLippe
Copy link

I think this change regresses the case where process is undefined in the browser. E.g. in the browser, you can't have a reference to a variable called process. Therefore, I think this is going to break that use case.

@Andarist
Copy link
Member Author

Andarist commented Feb 21, 2019

That's why I'm building ./dist/xstate.esmodules-browsers.js bundle which should be browser compatible (no references to process). It's the same situation as in reduxjs/redux#3143 , redux-saga/redux-saga#1717 , etc

@TimvdLippe
Copy link

Ah okay. If that works, good! I am not an expert in rollup, so I don't really understand how it is makes sure it removes the reference. Is it the toplevel: true?

@Andarist
Copy link
Member Author

toplevel: true is for uglify/terser - so it can mangle "top level" variables - otherwise it assumes they might be assigned as globals to window object. I think this actually should be the default for module sources, but maybe logic handling this wasnt implemented yet

I am not an expert in rollup, so I don't really understand how it is makes sure it removes the reference

This is done by rollup-plugin-replace

rollup.config.js Outdated Show resolved Hide resolved
@Andarist
Copy link
Member Author

@davidkpiano friendly 🏓

@davidkpiano davidkpiano merged commit c9e34af into statelyai:master Feb 25, 2019
@davidkpiano
Copy link
Member

Thank you!

@Andarist Andarist deleted the fix/process-minification branch August 6, 2019 14:15
@Andarist Andarist mentioned this pull request Nov 7, 2019
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.

3 participants