Making package
handle more complex use cases.
#4828
Labels
pkg:svelte-package
Issues related to svelte-package
Milestone
Describe the problem
We use the
svelte-kit package
command to give us a clean, publishable asset at build time.Whilst this works fine for a lot of simple cases, small components etc, we have the following use cases which it doesn't handle well:
As real example, I might have the following structure:
This will, by default, generate the following
package/package.json
attributesthis is because
package
collapses the internal structure, and writes exports. This is fine for modern + SvelteKit consumers.I don't actually want the two components exported individually so I do this:
which gives me:
However in Sapper, I need to ensure that "main" and "module" aren't specified if the package is "type":"module", because these cause errors, so I need to instead specify exports within the source
package.json
:when I run package now, it generates the same content as before, but overrides what is generated using the source
package.json
, which is a reasonable thing to do:The issue here is that,
package
generates a flat file structure:so these overridden paths are wrong.
Ultimately this leaves me in a position where I can write a package which works in Prod or Dev, in a monorepo or not, or in Sapper. It's a bit awkard.
Describe the proposed solution
My proposal would be that we enhance the
exports
configuration property.Right now it returns a simple Boolean to determine whether a specific file should be included or not.
Definitions within the source
package.json
are then merged (applied) to the output.My proposal would be that we allow the
exports
function to receive two parameters:a Map, of the generated output, before any changes
a Map of the source
exports
from the originalpackage.json
(though you could probably just importpackage.json
to get this.and allow you to modify it before returning it.
Alternatives considered
Map
and allow you to modify it to your needs.[ export_name, export_path ]
svelte-kit package
that it shouldn't override values from the source file.Importance
would make my life easier
Additional Information
blocking all use of
package
, or rather, making it very much redundant.The text was updated successfully, but these errors were encountered: