-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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!: migrate to ESM #8178
feat!: migrate to ESM #8178
Conversation
➜ ls -l *.tgz
-rw-r--r-- 1 antfu staff 1036930 May 15 09:11 vite-3.0.0-alpha.0-cjs.tgz
-rw-r--r-- 1 antfu staff 1077340 May 15 08:32 vite-3.0.0-alpha.0-esm.tgz
➜ ls -lh *.tgz
-rw-r--r-- 1 antfu staff 1.0M May 15 09:11 vite-3.0.0-alpha.0-cjs.tgz
-rw-r--r-- 1 antfu staff 1.0M May 15 08:32 vite-3.0.0-alpha.0-esm.tgz Bundle size diff is not significant. |
This is a great move since it effectively gets rid of the ESM-only error for Vite users. (This is the We can say whatever we want about Node.js's ESM-only strategy and the folks like |
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.
After building, it looks like the raw individual .d.ts file are still left in dist/node/*
. Using api-extractor I think these are bundled and can be removed. I'm not sure what's causing it though.
Tested in VitePress and it works! |
"require": "./index.cjs" | ||
}, | ||
"./client": { | ||
"types": "./client.d.ts" |
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.
This ./client
export is needed when using the new nodenext
module resolution in the upcoming TypeScript 4.7 release.
As it stands now, using Vite 2.9.9
with typescript 4.7.1-rc
+ module: "nodenext"
does not work because the compiler cannot access client.d.ts
as it is not explicitly exported.
/// <reference types="vite/client" />
Looking forward to this getting into the 3.0.0
release.
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.
🔥
@antfu I think you can merge it and release a new alpha with it when you see fit.
Let's merge it to try in the next alpha! |
"main": "./dist/node/index.js", | ||
"module": "./dist/node/index.js", |
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 we could remove these 2 fields since Vite 3 supports Node 14+, Node 12+ supports exports
field and exports
takes priority than main
and module
so Node.js will never reach these 2 fields.
"types": "./client.d.ts" | ||
}, | ||
"./terser": { | ||
"require": "./dist/node-cjs/terser.cjs" |
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.
TS complains here as missing declaration file.
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.
What version of TS and what “module” and/or “moduleResolution” settings are you using in your tsconfig.json file?
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.
Tried with TS 4.6 (node) and 4.7-rc1 (nodenext) with "module" being "esnext"
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 mean "./terser"
, it is being removed here https://github.com/vitejs/vite/pull/8049/files#diff-949e137b027a941e9a8dabb980971ab5b7147f895fc06ab2ff0bb0923d981606L23
close #5839
Breaking changes
vite
now hastype: module
.js
underdist/
are now ESMindex.cjs
is created for CJS compactiblity, which proxies ESM APIs without a full CJS build.formatPostcssSourceMap
is now asyncresolvePackageEntry
resolvePackageData