Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Sep 14, 2023
1 parent ea65971 commit ce7b03b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For other projects, there are a few general approaches:

- **Configure ESM as default, opt-in to CJS if needed:** Add `"type": "module"` in the project `package.json`. All `*.js` files are now interpreted as ESM and needs to use the ESM syntax. You can rename a file with the `.cjs` extension to keep using CJS instead.
- **Keep CJS as default, opt-in to ESM if needed:** If the project `package.json` does not have `"type": "module"`, all `*.js` files are interpreted as CJS. You can rename a file with the `.mjs` extension to use ESM instead.
- **Dynamically import Vite:** If you need to keep using CJS, you can dynamically import Vite using `import('vite')` instead. This requires your code to be written in an `async` context, but should still be trivial as Vite's API is mostly asynchronous.
- **Dynamically import Vite:** If you need to keep using CJS, you can dynamically import Vite using `import('vite')` instead. This requires your code to be written in an `async` context, but should still be manageable as Vite's API is mostly asynchronous.

If you're unsure where the warning is coming from, you can run your script with the `VITE_CJS_TRACE=true` flag to log the stack trace:

Expand Down
1 change: 1 addition & 0 deletions packages/vite/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ unsupportedCJS.forEach((name) => {

function warnCjsUsage() {
if (process.env.VITE_CJS_IGNORE_WARNING) return
globalThis.__vite_cjs_skip_clear_screen = true
const yellow = (str) => `\u001b[33m${str}\u001b[39m`
const log = process.env.VITE_CJS_TRACE ? console.trace : console.warn
log(
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ cli
`\n ${colors.green(
`${colors.bold('VITE')} v${VERSION}`,
)} ${startupDurationString}\n`,
{ clear: !server.config.logger.hasWarned },
{
clear:
!server.config.logger.hasWarned &&
!(globalThis as any).__vite_cjs_skip_clear_screen,
},
)

server.printUrls()
Expand Down

0 comments on commit ce7b03b

Please sign in to comment.