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

Fix sideEffects package configuration for "auto" entrypoints #194

Merged
merged 1 commit into from
Feb 26, 2021

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 26, 2021

The package uses sideEffects along with ES Module exports to allow consuming projects to optimize the amount of code generated when using individual components from the package, via dead-code elimination / "tree shaking". sideEffects instructs the bundler that there are no side-effects in importing the code, and that it's safe to discard code except for direct references to exported members.

However, this project also distributes an "auto" version, which is intended to automatically handle initialization for all components simply by being loaded:

import 'identity-style-guide/auto';

This requires side effects, and therefore must be made an exception by passing paths as an array to sideEffects (see documentation). Otherwise, no code will be loaded since Webpack will assume it's safe to eliminate all unreferenced exports, and since there are no referenced exports, all code would be omitted.

In the meantime, projects using the current published version can work around this by configuring Webpack to override the package's default sideEffects value (reference):

module.rules: [
  {
    include: path.resolve('node_modules', 'identity-style-guide'),
    sideEffects: true
  }
]

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like JSON to me 🤷

@aduth aduth merged commit 99405e7 into main Feb 26, 2021
@aduth aduth deleted the aduth-side-effects branch February 26, 2021 18:10
@aduth aduth added the performance Changes which seek to improve performance label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Changes which seek to improve performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants