-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Changes from all commits
b65773c
ce8b9cc
2302063
ab204d0
63012c5
f8ce0e6
0f81c98
cc58a9b
5bea908
0738eb9
19292a3
9f8c74c
0e1da14
de67745
aa07d3f
96622ca
28e9a34
0f1e540
1140920
1cd5be8
e481971
8252f19
439fef7
e9bccb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
|
||
// type utils | ||
module.exports.defineConfig = (config) => config | ||
|
||
// proxy cjs utils (sync functions) | ||
Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs')) | ||
|
||
// async functions, can be redirect from ESM build | ||
const asyncFunctions = [ | ||
'build', | ||
'createServer', | ||
'preview', | ||
'transformWithEsbuild', | ||
'resolveConfig', | ||
'optimizeDeps', | ||
'formatPostcssSourceMap', | ||
'loadConfigFromFile' | ||
] | ||
asyncFunctions.forEach((name) => { | ||
module.exports[name] = (...args) => | ||
import('./dist/node/index.js').then((i) => i[name](...args)) | ||
}) | ||
|
||
// some sync functions are marked not supported due to their complexity and uncommon usage | ||
const unsupportedCJS = ['resolvePackageEntry', 'resolvePackageData'] | ||
unsupportedCJS.forEach((name) => { | ||
module.exports[name] = () => { | ||
throw new Error( | ||
`"${name}" is not supported in CJS build of Vite 3.\nPlease use ESM or dynamic imports \`const { ${name} } = await import('vite')\`.` | ||
) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
{ | ||
"name": "vite", | ||
"version": "3.0.0-alpha.1", | ||
"type": "module", | ||
"license": "MIT", | ||
"author": "Evan You", | ||
"description": "Native-ESM powered web dev build tool", | ||
"bin": { | ||
"vite": "bin/vite.js" | ||
}, | ||
"main": "dist/node/index.js", | ||
"types": "dist/node/index.d.ts", | ||
"main": "./dist/node/index.js", | ||
"module": "./dist/node/index.js", | ||
"types": "./dist/node/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/node/index.d.ts", | ||
"import": "./dist/node/index.js", | ||
"require": "./index.cjs" | ||
}, | ||
"./client": { | ||
"types": "./client.d.ts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This As it stands now, using Vite
Looking forward to this getting into the |
||
}, | ||
"./terser": { | ||
"require": "./dist/node-cjs/terser.cjs" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. If you mean |
||
} | ||
}, | ||
"files": [ | ||
"bin", | ||
"dist", | ||
"client.d.ts", | ||
"index.cjs", | ||
"src/client", | ||
"types" | ||
], | ||
|
@@ -29,12 +45,12 @@ | |
}, | ||
"homepage": "https://github.com/vitejs/vite/tree/main/#readme", | ||
"scripts": { | ||
"dev": "rimraf dist && rollup -c -w", | ||
"dev": "rimraf dist && pnpm run build-bundle -w", | ||
"build": "rimraf dist && run-s build-bundle build-types", | ||
"build-bundle": "rollup -c", | ||
"build-bundle": "rollup --config rollup.config.ts --configPlugin esbuild", | ||
bluwy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"build-types": "run-s build-temp-types patch-types roll-types", | ||
"build-temp-types": "tsc --emitDeclarationOnly --outDir temp/node -p src/node", | ||
"patch-types": "ts-node scripts/patchTypes.ts", | ||
"patch-types": "esno scripts/patchTypes.ts", | ||
"roll-types": "api-extractor run && rimraf temp", | ||
"lint": "eslint --ext .ts src/**", | ||
"format": "prettier --write --parser typescript \"src/**/*.ts\"", | ||
|
@@ -75,6 +91,7 @@ | |
"dotenv": "^14.3.2", | ||
"dotenv-expand": "^5.1.0", | ||
"es-module-lexer": "^0.10.5", | ||
"esno": "^0.16.3", | ||
"estree-walker": "^2.0.2", | ||
"etag": "^1.8.1", | ||
"fast-glob": "^3.2.11", | ||
|
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 andexports
takes priority thanmain
andmodule
so Node.js will never reach these 2 fields.