-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
feat(tree-shaking): enable browser target webpack tree-shaking #21055
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const isCalledByBundler = caller => caller.name.startsWith('@rollup'); | ||
|
||
module.exports = api => { | ||
const calledByBundler = api.caller(isCalledByBundler); | ||
const transformEnvVariables = | ||
!calledByBundler && | ||
process.env.NODE_ENV && | ||
process.env.BROWSER !== undefined; | ||
|
||
return { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
bugfixes: true, | ||
}, | ||
], | ||
['@babel/preset-typescript'], | ||
], | ||
plugins: [ | ||
[ | ||
'@babel/plugin-proposal-class-properties', | ||
{ | ||
loose: true, | ||
}, | ||
], | ||
[ | ||
'@babel/plugin-proposal-private-methods', | ||
{ | ||
loose: true, | ||
}, | ||
], | ||
[ | ||
'@babel/plugin-proposal-private-property-in-object', | ||
{ | ||
loose: true, | ||
}, | ||
], | ||
transformEnvVariables && [ | ||
'transform-inline-environment-variables', | ||
{ | ||
include: ['NODE_ENV', 'BROWSER'], | ||
}, | ||
], | ||
transformEnvVariables && [ | ||
'minify-dead-code-elimination', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we consider https://github.com/solana-labs/solana/pull/21055/files#r759707513, then this becomes unnecessary as well, the consumer's bundler / minifier will remove the bit of dead code: if (!process.env.BROWSER) {
agentManager = new AgentManager(useHttps);
} |
||
{ | ||
keepFnName: true, | ||
keepFnArgs: true, | ||
keepClassName: true, | ||
}, | ||
], | ||
transformEnvVariables && [ | ||
'babel-plugin-transform-remove-imports', | ||
{ | ||
test: 'agent-manager', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really satisfied by this solution, forces the build to be aware that a specific import is unused in specific conditions ̛& needs to be removed. I believe it might be best to not remove the import, and in fact ship the code containing references to |
||
}, | ||
], | ||
].filter(Boolean), | ||
}; | ||
}; |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This on the other hand, I think is good to keep in any case, since it enables not forcing consumers to inject themselves inlined
process.env.BROWSER
&process.env.NODE_ENV
values in their builds (even though,process.env.NODE_ENV
is injected by most bundlers automatically today)