Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

treeshake.pureExternalModules not run after terser minification. #15

Open
azizhk opened this issue Nov 20, 2018 · 3 comments
Open

treeshake.pureExternalModules not run after terser minification. #15

azizhk opened this issue Nov 20, 2018 · 3 comments

Comments

@azizhk
Copy link

azizhk commented Nov 20, 2018

When used with treeshake.pureExternalModules, essentially all unused imports after terser minification should be removed. But I guess that happens before the minification and thus persists.

Minimal reproducing case: https://repl.it/repls/SoupyWigglyExtraction
Here it should not log anything. (The last line of index.js)

This might not be a bug with rollup-plugin-terser or rollup or terser individually per se, but maybe if we can change the order this might work.

Related: terser/terser#168 which might require some effort if tackled only from terser's side.

@bvaughn
Copy link

bvaughn commented Mar 4, 2019

Looks like adding this plug-in also removes the #__PURE__ annotations from the resulting bundle (at least based on my experiments with using it in react-window)

@azizhk
Copy link
Author

azizhk commented Mar 5, 2019

Hi @bvaughn
I think your issue is with terser. I tried a bunch of settings but could not retain the comments with just terser: https://repl.it/repls/ProudClientsideGreenware
And as this plugin is a wrapper around terser, I don't think this plugin will be able to retain the comments unless fixed in terser. Let's open an issue with terser for this.

I think you have another step for tree shaking after your code goes through terser where it is unable to treeshake because #__PURE__ comments are no longer there.

My issue is slightly different. My #__PURE__ code + comment gets removed correctly but rollup's treeshake.pureExternalModules step happens before my code is passed to terser and not after so my unused imports are still retained. (For which I am doing regex for my agadoo like tree shaking tests)

@bvaughn
Copy link

bvaughn commented Mar 5, 2019

I think your issue is with terser.

Agreed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants