"module" publishing; all exports must be explicitly defined
iambumblehead opened this issue · comments
if dependents use other files than the main exported file, those other files must be explicitly exported at the package.json.
I'm sharing this here as a sort of starting point in case the package.json must define exports. There are many different ways of doing something like this, but the below (basic) pattern would allow another package to do something like import attachto from 'snabbdom/build/helpers/attachto.js'
{
"name": "snabbdom",
"exports": {
".": {
"import": "./build/index.js",
"types": "./build/index.d.ts",
"default": "./build/index.js"
},
"./build/helpers/*.js": "./build/helpers/*.js",
"./build/modules/*.js": "./build/modules/*.js"
}
}
related #1085 (comment)
cc @mreinstein
Why would a package want to import the build filed individually? The problem with this is that it basically makes the file layout into the package API. This means that every internal change moving files/functions around becomes a breaking change.
I would prefer to keep the current API
I agree with @jvanbruegge. Importing individual files is not something that is supported. That is how the package worked many years ago, but we explicitly moved away from that with tree-shaking now being able to eliminate any unused parts.