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

Ensure import()ed dependencies are always dynamically imported #208

Open
fregante opened this issue Feb 9, 2024 · 0 comments
Open

Ensure import()ed dependencies are always dynamically imported #208

fregante opened this issue Feb 9, 2024 · 0 comments

Comments

@fregante
Copy link
Collaborator

fregante commented Feb 9, 2024

If you first import('react') and then import "react" in the same bundle, Webpack will not create a secondary chunk, it will just inline it.

In a large application, it's not easy to keep track of all the import decisions, so one optimization (deferred loading via import()) can be undone and left unnoticed forever.

We can now enforce that some dependencies are always dynamically imported:

  • ban the static imports of a set of dependencies (i.e. always import canvas-confetti via import())
  • remind developers to update this set of dependencies every time the linter encounters a new import("new-dependency")

Both of these are enforceable via no-restricted-syntax

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant