Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

quantizor
Copy link

@quantizor quantizor commented Nov 14, 2022

When building a library, "pure" comments are often added to various bits and pieces to ensure tree-shaking works properly in the destination bundle. Compression via terser will automatically drop these hints in some cases, so disabling compression serves the purpose of leaving total minification up to the destination bundler.

At the moment, rollup takes these pure comments into account as well when bundling which can lead to early-dropping of statements that are meant to be dropped later in the destination bundler. We should disable "pure" comment-related treeshaking in microbundle when compression is turned off to ensure this use case works as expected.

For example, here's a use case which involves setting displayName on a component in a way that if the component is tree-shaken, the displayName goes away as well:

export const Foo = (props) => <div {...props} />

/*#​__PURE__*/Object.assign(Foo, { displayName: 'Foo' });

…sabled

When building a library, "pure" comments are often added to various bits and pieces to ensure tree-shaking works properly in the destination bundle. Compression via terser will automatically drop these hints in some cases, so disabling compression serves the purpose of leaving total minification up to the destination bundler.
@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2022

⚠️ No Changeset found

Latest commit: 4b968ba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@developit
Copy link
Owner

@probablyup I'm curious how you ended up with that code from the snippet - normally I'd expect the pure annotation to apply to the Object.assign property access, not the function call:

export const Foo = (props) => <div {...props} />

(/*#​__PURE__*/ Object.assign)(Foo, { displayName: 'Foo' });

Is the annotation something you're adding? Or a Babel plugin?

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

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.