Repository navigation
Add Built-in Auto Import Support for Components #94330
Closed
amirmmolazemi
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Goals
Non-Goals
Background
Why do we need this?
Current Problem
Developers repeatedly write and maintain import statements for frequently used components.
Example:
In large applications, these imports:
Expected Benefits
Proposal
How should this feature be implemented?
High-Level Approach
Implement a compile-time auto-import system integrated into the build pipeline.
Component Discovery
Allow developers to configure directories:
The compiler scans these directories and creates a component registry.
JSX Analysis
When the compiler encounters:
It checks whether
ButtonandCardare already imported.If not, it looks them up in the registry.
Import Injection
Before compilation, imports are automatically injected:
This means React, TypeScript, bundling, and tree-shaking continue to work normally.
TypeScript Support
Generate a declaration file:
or use a generated registry to provide IntelliSense and type safety.
Name Collision Handling
If two components share the same name:
the build should fail with a clear error:
This prevents ambiguous resolution.
Performance Considerations
Example Developer Experience
Without auto-imports:
With auto-imports:
All reactions