Remove Relative Imports in Favor of Node's imports config in package.json #389
Replies: 3 comments 5 replies
-
There’s also self-referencing a package by its name, which is a different, even less well-known feature than {
"name": "~",
"type": "module",
"exports": {
"./*": "./*"
}
} Then you can import a You could also use the {
"name": "~",
"type": "module",
"exports": {
"./*": "./src/*"
}
} Then if you move It doesn’t need to be |
Beta Was this translation helpful? Give feedback.
-
Does this work without config everywhere? Like this work on Remix and Vitest? Because for TS path aliases you need a plugin in Vitest, will this work without that too? |
Beta Was this translation helpful? Give feedback.
-
This sounds like a great approach for smaller projects! If you start to see some growth in the size of the repo, I'd recommend using a monorepo, which comes with added benefits such as import control (e.g. UI packages are prevented from importing business logic packages). One thing I like especially is in nx where you can tag your packages (akin to root-level folders in your current setup) and then setup rules e.g. I started noticing telemetry/tracing libraries (like Sentry) creeping into areas where they shouldn't be, so a simple one liner can get things back into shape quickly |
Beta Was this translation helpful? Give feedback.
-
A few days ago we removed path aliases. We're only kinda bringing that back. Instead, we're utilizing the Node.js standard
package.json
"imports"
config to get the same thing:Read the decision document here: https://github.com/epicweb-dev/epic-stack/blob/main/docs/decisions/031-imports.md
The commit is here: 4989782
Beta Was this translation helpful? Give feedback.
All reactions