Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable support for exports condition #502

Merged
merged 3 commits into from Nov 21, 2022

Conversation

dominikg
Copy link
Member

This PR enables using an export condition svelte to point at svelte source files.

eg this exports map

	"exports": {
		"./*": {
			"svelte": "./src/components/*"
		},
		".": {
			"svelte": "./index.js"
		}
	}

allows you to either import {SomeThing} from 'some-lib' when index.js exports SomeThing, or import SomeThing from 'some-lib/SomeThing.svelte' if you prefer a deep import to avoid the index.

This is a very simplistic example and the real usecase is to still allow exporting compiled svelte files or other js files via the import condition.

See https://nodejs.org/api/packages.html#conditional-exports for what you can do with export conditions.

@dominikg
Copy link
Member Author

dominikg commented Nov 19, 2022

do we need additional tests, eg a scenario with mixes svelte field and exports condition? Is the usage i described above what we want to go for?
i tried using the .svelte extension with glob but it didn't work even if the node docs show tha *.js is a thing.

	"exports": {
	       // boohoo, didn't work in my tests
		"./*.svelte": {
			"svelte": "./src/components/*.svelte"
		},
		".": {
			"svelte": "./index.js"
		}
	}

We only ever expect libraries to use the .svelte extension with preprocessed .svelte output, never other extensions like .svx that require additional markup preprocessors to be present, correct?

@benmccann
Copy link
Member

I wonder if it's just *.svelte that doesn't work or if other extensions are affected. My guess is that it's an existing Vite bug, but it might be nice to confirm and file an issue.

@bluwy
Copy link
Member

bluwy commented Nov 19, 2022

i tried using the .svelte extension with glob but it didn't work even if the node docs show tha *.js is a thing.

Yeah I think this should technically work too, hoping it's only a bug on not some hidden nodejs spec.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit but lgtm!

@dominikg dominikg merged commit 25009f2 into main Nov 21, 2022
@dominikg dominikg deleted the feat/svelte-exports-condition branch November 21, 2022 22:31
@github-actions github-actions bot mentioned this pull request Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants