-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
It's nice to allow addons to import themselves by name, especially so that their tests and demos are importing things the same way a consuming app would, which aids learning.
The main reason it doesn't already work nicely is that package.json exports points at dist, not src.
One option is to create a dedicated export condition:
"exports": {
".": {
"addon-development": "./src/index.ts",
"default": "./dist/index.js"
},which can be enabled in vite.config.js like:
resolve: {
conditions: ['addon-development']
}However, I realized this creates a hazard. When your addon is consumed by another addon, that addon may also opt into the "addon-development" condition and then it will try to consume your unbuilt sources, which is definitely not desirable.
So it seems that if we want to use this pattern, we'd have to either put the package name into the condition name:
"exports": {
".": {
"developing-@ef4/example-package": "./src/index.ts",
"default": "./dist/index.js"
},Or have a prepublish step that deletes these extra conditions so that people installing your package never see them.