feat: expose dist paths as root paths via package.json export field #3274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Enable writing imports like
import "@ui5/webcomponents/Button.js"
instead of
import "@ui5/webcomponents/dist/Button.js"
The
dist
folder is a development artefact and is not relevant for application developers, so this becomes a more developer friendly way of consuming ui5 webcomponents.This feature relies on the package.json exports field and should be considered only if it is supported. The original import paths with
dist
remain available and are the only official imports. Users of this features must take care that their build tool has the necessary support and that multiple copies of the same module do not end up in the final bundle in case they are referenced by both import paths and the build tool does not handle this correctly (checked to work correctly with rollup and webpack at this time)if for example app developers write imports like
since ToggleButton internally imports
import "@ui5/webcomponents/dist/Button.js"
there should be just one copy of the
Button
module even if it is imported by both paths.Remarks
Other files that are not actual modules but are used by tools via
require.resolve
to get the correct monorepo folder need to also be exposed in the exports field (examples are the.hbs
files insrc
for template includes, the.port
file used by the tests and the bundle files used by rollup)resolves #3208
alternative considered in #3292