-
-
Notifications
You must be signed in to change notification settings - Fork 106
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/esm #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only nitpicks
@@ -15,9 +15,9 @@ | |||
"test:ci:serve": "cross-env VITE_PRESERVE_BUILD_ARTIFACTS=1 jest --verbose --no-cache --runInBand --force-exit --ci --json --outputFile=\"temp/serve/jest-results.json\"", | |||
"test:ci:build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 jest --verbose --no-cache --runInBand --force-exit --ci --json --outputFile=\"temp/build/jest-results.json\"", | |||
"lint": "eslint --ignore-path .gitignore '**/*.{js,ts,svelte,html,svx,md}'", | |||
"lint:fix": "pnpm lint -- --fix", | |||
"lint:fix": "pnpm run lint -- --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pnpm added a feature recently to allow you to drop the run
part. Either way I feel like this bloats the PR - makes it harder to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that feature made me add it back, i wasn't sure if it would prefer a lint
dependency over the lint script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use a named export you can skip the require('@sveltejs/vite-plugin-svelte').default
stuff.
And since you're adding "exports"
map support and type: module
, this is already a breaking change, so might as well lean into it further and add the named export. The benefit of this is that it's more consistent for the user, and the type definitions will work for both ESM and CJS
My 2c. I'd personally prefer if we stick with default exports in contrary to @lukeed's suggestion, to be consistent with Vite's plugin ecosystem. On that topic, I also agree with @antony that we should encourage ESM in the Vite config files. |
Thank you for all your comments. Greatly appreciated ❤️ I like @lukeed suggestion of a named export and had thought about it too, but ultimately went with the default setup from other vite plugins @bluwy mentioned. Sharable typings are a valid reason to do it and maybe we can start a trend for other vite plugins to follow? I'd love to ditch cjs completely but feel thats a bit too soon. Esp. because right now it is still needed for tests with jest. Regarding more prominent esm examples, should the playgroud be spit into e2e and examples section? |
updated to named export but still included a default export with a deprecation warning: Without the default export, sveltekit breaks until updated (which includes the test in playground/kit-node) |
I'm still not sure if a named
Forgive me if I'm not understanding properly, but how actually does type definitions work for CJS, since types imports and exports are usually done in ESM contexts. I don't think it's a strong argument to use named exports. And shouldn't |
regarding default export vs named export: i asked about it on vite discord and while most plugins use a default export, there is eg. vite-plugin-pwa that uses a named export. here are the links to the discussions back at terser plugin: if it is technically more consistent i don't care much about two additional {} in an import statement, but it seems others do care and i'd like to avoid having discussions about this in the future, so ideally we can decide on a way forward here and stick to it. so what should it be?
@lukeed maybe you can explain more about the benefits of the named export for cjs. |
Another option would be to export as named and default export, but only put the named export in the type definitions and docs and make that the preferred but not required way |
TypeScript only supports 1 @TrySound cares about this too & that's why |
I guess it comes down to whether we want an awkward syntax for ESM or CJS. Given a majority of our userbase is on ESM (since the default Vite starter config is in ESM), I'd prefer default exports to please the crowd. If it all comes down to preference, perhaps a public poll could end this once and for all. EDIT: Made a mini poll on Vite discord. |
…export to changelog
removed the default export completely (as expected this caused the kit-node tests to fail). |
conversion to esm. superseeds #49