Add sideeffects: false to package.json
twavv opened this issue · comments
See title.
Allows for deadcode elimination when not the module is imported but not actually used.
This comes up for me when using NextJS where one frequently writes server side code as a getServerSideProps
function. I want to import Node's crypto module but don't need it for the browser -- but webpack is unable to remove the import even though Next does remove the getServerSideProps
function).
The workaround is to add
module.exports = {
node: {
crypto: "empty"
}
}
to the webpack config.
@travigd Can you use a dynamic import instead?
export async function getServerSideProps() {
const crypto = await import('crypto');
}
Yes, but this should still be fixed. :)
I'm currently just using the webpack workaround described above.
Probably best not to conflate multiple things in the same PR.
Would it be best to rather make a separate PR after #200 is pushed to have this fixed?
I'd think so.
Fixed in b638139