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

Add "pure"-annotations to the source to aid code minification #343

Open
Avaq opened this issue May 31, 2019 · 3 comments
Open

Add "pure"-annotations to the source to aid code minification #343

Avaq opened this issue May 31, 2019 · 3 comments

Comments

@Avaq
Copy link
Member

Avaq commented May 31, 2019

Tools like Rollup and UglifyJS can make better optimizations if they know certain pieces of code will never have side-effects. One way to let these tools know is via /*#__PURE__*/-annotations.

@Avaq Avaq changed the title Add "pure"-annotations to the source to aid code minifcation Add "pure"-annotations to the source to aid code minification May 31, 2019
@Avaq
Copy link
Member Author

Avaq commented Oct 29, 2019

There's a chance that even after marking things as pure, tree shaking still won't be very beneficial, due to the way debugMode is implemented. When calling debugMode(true), a function deep down in the Fluture code is replaced. This function is used by the entire Fluture codebase. And as the possibility for it to be replaced should be considered a mutation, I fear that by extension the entire codebase should be considered mutable. I'll have to do some experiments to verify whether this is the case, and if I can work around it.

@OliverJAsh
Copy link

We would love to use Fluture at Unsplash but unfortunately we're blocked by this. Is there anything we can do to help you move this forward?

@Avaq
Copy link
Member Author

Avaq commented Jan 16, 2022

I think the most straight-forward approach is to reimplement debug mode using an environment variable, checking process.env.FLUTURE_DEBUG or perhaps self.FLUTURE_DEBUG in browsers, making it so once the module resolves, the debug mode is determined, and can't be changed later.

This will have the added benefit that multiple compatible versions of Fluture that have been installed side by side will all use the same source to enable or disable their debug modes, giving users who enable debug mode a more uniform experience.

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

No branches or pull requests

2 participants