Skip to content

Commit

Permalink
fix: specify own Node version as target when bundling config files, c…
Browse files Browse the repository at this point in the history
…loses vitejs#17291
  • Loading branch information
SegaraRai committed May 24, 2024
1 parent e7d38ab commit 2517216
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ async function bundleConfigFile(
absWorkingDir: process.cwd(),
entryPoints: [fileName],
write: false,
target: ['node18'],
target: [`node${process.versions.node}`],
platform: 'node',
bundle: true,
format: isESM ? 'esm' : 'cjs',
Expand Down
1 change: 1 addition & 0 deletions playground/config/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ it('loadConfigFromFile', async () => {
4,
],
],
"jsonValue": "@vite/test-config-entry",
"moduleCondition": "import condition",
}
`)
Expand Down
23 changes: 23 additions & 0 deletions playground/config/packages/entry/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// test if the json file is imported correctly

let value: string

// try import attributes
try {
value = (
await import('./package.json', {
with: { type: 'json' },
})
).default.name
} catch {}

// try import assertions
try {
value = (
await import('./package.json', {
assert: { type: 'json' },
})
).default.name
} catch {}

export const jsonValue = value
2 changes: 2 additions & 0 deletions playground/config/packages/entry/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import moduleCondition from '@vite/test-config-plugin-module-condition'
import { array } from '../siblings/foo'
import { jsonValue } from './json'

export default {
array,
jsonValue,
moduleCondition,
}

0 comments on commit 2517216

Please sign in to comment.