Skip to content

Commit b7e0e42

Browse files
sheremet-vabluwyhi-ogawa
authored
feat: use module runner to import the config (#18637)
Co-authored-by: bluwy <[email protected]> Co-authored-by: Hiroshi Ogawa <[email protected]>
1 parent 93d5443 commit b7e0e42

File tree

23 files changed

+357
-90
lines changed

23 files changed

+357
-90
lines changed

docs/config/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ You can also explicitly specify a config file to use with the `--config` CLI opt
2222
vite --config my-config.js
2323
```
2424

25+
::: tip BUNDLING THE CONFIG
26+
By default, Vite uses `esbuild` to bundle the config into a temporary file. This can 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 instead - it 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.
27+
:::
28+
2529
## Config Intellisense
2630

2731
Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:

docs/guide/cli.md

Lines changed: 71 additions & 67 deletions
Large diffs are not rendered by default.

packages/vite/index.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const asyncFunctions = [
2121
'loadConfigFromFile',
2222
'preprocessCSS',
2323
'createBuilder',
24+
'runnerImport',
2425
]
2526
asyncFunctions.forEach((name) => {
2627
module.exports[name] = (...args) =>

packages/vite/src/module-runner/esmEvaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import type { ModuleEvaluator, ModuleRunnerContext } from './types'
1313

1414
export class ESModulesEvaluator implements ModuleEvaluator {
15-
startOffset = getAsyncFunctionDeclarationPaddingLineCount()
15+
public readonly startOffset = getAsyncFunctionDeclarationPaddingLineCount()
1616

1717
async runInlinedModule(
1818
context: ModuleRunnerContext,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface Test {
2+
field: true
3+
}
4+
5+
export const test: Test = {
6+
field: true,
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'ok'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => import('./dynamic-import-dep')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Plugin } from 'vite'
2+
3+
export default function testPlugin(): Plugin {
4+
return {
5+
name: 'test',
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import parent from '@vitejs/parent'
2+
3+
export default {
4+
__injected: parent.child,
5+
}

0 commit comments

Comments
 (0)