-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
V2: Inline process.browser for better code elimination #3688
V2: Inline process.browser for better code elimination #3688
Conversation
Why would you set that? If a bundler doesn't support it and/or without a bundler? |
When not in a browser, I would not expect this line to be in the code at all, as it is only inserted when polyfilling node process: /~https://github.com/defunctzombie/node-process/blob/master/browser.js#L156 I can bearly find use cases for this, so it is really hard to decide on that. Maybe this could harm in a test environment where you want to mock browser behavior? |
Not sure if we should replace it on node as well. It isn't a "standardized" property on
Is that common (where the value differs from
parcel/packages/core/core/src/public/Environment.js Lines 15 to 24 in 7cf6a3b
|
Okay, I agree with not touching it on NodeJS and updated the PR. I guess electron is handled with |
Either adding a
or passing this as the second argument to |
Alright, tests are in place now. Unfortunately, parcel/packages/core/test-utils/src/utils.js Line 186 in 7cf6a3b
Is this expected or a bug? Based on the types there is a mismatch as far as I can see: parcel/packages/core/types/index.js Line 76 in 7cf6a3b
|
Yeah, that was never updated from Parcel 1. It should be: case 'browser':
...
case 'node':
case 'electron-main':
....
case 'electron-renderer':
...
default:
throw new Error('Unknown target ' + target); Could you please update that as well? |
Okay, I hope that everything works now. Thank you for your support on this :) |
For |
@mischnic Alright, I pushed my next try. I hope everything is in place now! |
@garthenweb could you rebase this PR on V2? |
Sure, will have a look on the weekend! |
36d4b20
to
15bee13
Compare
15bee13
to
960ca84
Compare
@DeMoorJasper The branch is rebased and up to date now. Tests are passing. I squashed the commits as this was the easiest way to rebase. Let me know if something is missing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks for rebasing this so quickly :)
↪️ Pull Request
Migrates #2583 to v2. This feature is heavily used in some projects and can save a lot of dead code to be eliminated.
I made two changes compared to v1:
process.browser = true
assignment that might be somewhere in the code is not replaced anymore but always set totrue
. Removing this line could lead to breaking the code in rare situations, but not changing it tootrue
would be inconsequent as well. Let me know if you have any thoughts about that.process.browser
is different fromprocess.env
which can change after build time on the server. Tests for Node and Electron as skipped for now, as all those tests were skipped so far. I expect this to be implemented later for v2.💻 Examples
See #2583.
🚨 Test instructions
Place
process.browser
somewhere in your code and see it is replaced withtrue
when build for the target browser.