You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 05302b0
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/config/index.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ export default {
14
14
}
15
15
```
16
16
17
-
Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM, e.g. `"type": "module"` in `package.json`. In this case, the config file is auto pre-processed before load.
17
+
Note that to use ES modules syntax in the config file, it should be in a file detected as ESM by Node.js, e.g. `.mjs` or `.js` with `"type": "module"` in closest `package.json`.
18
18
19
19
You can also explicitly specify a config file to use with the `--config` CLI option (resolved relative to `cwd`):
20
20
@@ -25,9 +25,7 @@ vite --config my-config.js
25
25
<ScrimbaLinkhref="https://scrimba.com/intro-to-vite-c03p6pbbdq/~05jg?via=vite"title="Configuring Vite">Watch an interactive lesson on Scrimba</ScrimbaLink>
26
26
27
27
::: tip CONFIG LOADING
28
-
By default, Vite uses [Rolldown](https://rolldown.rs/) to bundle the config into a temporary file and load it. This may cause issues when importing TypeScript files in a monorepo. If you encounter any issues with this approach, you can specify `--configLoader runner` to use the [module runner](/guide/api-environment-runtimes.html#modulerunner) instead, which will not create a temporary config and will transform any files on the fly. Note that module runner doesn't support CJS in config files, but external CJS packages should work as usual.
29
-
30
-
Alternatively, if you're using an environment that supports TypeScript (e.g. `node --experimental-strip-types`), or if you're only writing plain JavaScript, you can specify `--configLoader native` to use the environment's native runtime to load the config file. Note that updates to modules imported by the config file are not detected and hence would not auto-restart the Vite server.
28
+
By default, Vite uses [Rolldown](https://rolldown.rs/) to bundle the config into a temporary file and load it. If you're using an environment that supports TypeScript (e.g. Node 22.18+), or if you're only writing plain JavaScript, you can specify `--configLoader native` to use the environment's native runtime to load the config file. `configLoader: 'native'` is planned to become the default in a future major version.
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1408
+
- \`__dirname\` (vite.config.js:3). Use \`import.meta.dirname\` instead
1409
+
- \`__filename\` (vite.config.js:4). Use \`import.meta.filename\` instead
1410
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
1411
+
]
1412
+
`)
1413
+
})
1414
+
1415
+
// uses a `.ts` config with TypeScript-only syntax; skipped on Node
1416
+
// versions without type stripping support
1417
+
test.skipIf(!supportsTypeStripping)(
1418
+
'warns on __dirname in a config using TypeScript syntax',
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1424
+
- \`__dirname\` (vite.config.ts:10). Use \`import.meta.dirname\` instead
1425
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1436
+
- import "./helper" without a file extension (vite.config.js:1). Add the file extension
1437
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1447
+
- import "./plugins" resolves to a directory index (vite.config.js:1). Import the index file directly
1448
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
1449
+
]
1450
+
`)
1451
+
})
1452
+
1453
+
test('warns on JSON import without attributes',async()=>{
1454
+
constmessages=awaitloadWithWarnings('json')
1455
+
expect(messages).toMatchInlineSnapshot(`
1456
+
[
1457
+
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1473
+
- import "./foo" resolves to a JSON file (vite.config.js:1). Import it with a \`.json\` extension and \`with { type: 'json' }\`
1474
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
1475
+
]
1476
+
`)
1477
+
})
1478
+
1479
+
test('does not warn on a native-compatible config',async()=>{
test('warns for an ESM file imported by a CJS config',async()=>{
1488
+
constmessages=awaitloadWithWarnings(
1489
+
'cjs-imports-esm',
1490
+
'vite.config.cjs',
1491
+
)
1492
+
expect(messages).toMatchInlineSnapshot(`
1493
+
[
1494
+
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1495
+
- \`__dirname\` (esm-helper.mjs:1). Use \`import.meta.dirname\` instead
1496
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
1497
+
]
1498
+
`)
1499
+
})
1500
+
1501
+
test('warns on ESM syntax in a config under a `type: commonjs` package',async()=>{
"(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite:
1506
+
- ESM syntax in a file loaded as CommonJS (vite.config.js:1). Use a \`.mjs\` extension or set \`"type": "module"\` in the closest package.json
1507
+
Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.",
0 commit comments