The package.json exports field can map import paths to package files.
It also allows for conditions depending on what requested the import:
https://nodejs.org/api/packages.html#conditional-exports
The standard ones are for JS modules (ESM/CJS), and it mentions “community” conditions like types and browser.
Webpack docs also mention style and sass, but it's unclear if that's actually supported in webpack, let alone in other bundlers:
https://webpack.js.org/guides/package-exports/#conditions
The style condition has some prior usage in some npm packages:
https://jaketrent.com/post/package-json-style-attribute/
If anything, it might be good to explicitly list files that should be accessible, for example:
{
"exports": {
"./dist/*.css": "./dist/*.css"
}
}
The
package.jsonexportsfield can map import paths to package files.It also allows for conditions depending on what requested the import:
https://nodejs.org/api/packages.html#conditional-exports
The standard ones are for JS modules (ESM/CJS), and it mentions “community” conditions like
typesandbrowser.Webpack docs also mention
styleandsass, but it's unclear if that's actually supported in webpack, let alone in other bundlers:https://webpack.js.org/guides/package-exports/#conditions
The
stylecondition has some prior usage in some npm packages:https://jaketrent.com/post/package-json-style-attribute/
If anything, it might be good to explicitly list files that should be accessible, for example:
{ "exports": { "./dist/*.css": "./dist/*.css" } }