Skip to content

Commit

Permalink
fix: respect top-level server.preTransformRequests (#19272)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 3, 2025
1 parent 7e6364d commit 12aaa58
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
94 changes: 94 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,97 @@ test('config compat 3', async () => {
]
`)
})

test('preTransformRequests', async () => {
async function testConfig(inlineConfig: InlineConfig) {
return Object.fromEntries(
Object.entries(
(await resolveConfig(inlineConfig, 'serve')).environments,
).map(([name, e]) => [name, e.dev.preTransformRequests]),
)
}

expect(
await testConfig({
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": true,
"custom": false,
"customFalse": false,
"customTrue": true,
"ssr": false,
}
`)

expect(
await testConfig({
server: {
preTransformRequests: true,
},
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": true,
"custom": true,
"customFalse": false,
"customTrue": true,
"ssr": true,
}
`)

expect(
await testConfig({
server: {
preTransformRequests: false,
},
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": false,
"custom": false,
"customFalse": false,
"customTrue": true,
"ssr": false,
}
`)
})
6 changes: 5 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,13 @@ export function resolveDevEnvironmentOptions(
consumer: 'client' | 'server' | undefined,
// Backward compatibility
skipSsrTransform?: boolean,
preTransformRequest?: boolean,
): ResolvedDevEnvironmentOptions {
const resolved = mergeWithDefaults(
{
...configDefaults.dev,
sourcemapIgnoreList: isInNodeModules,
preTransformRequests: consumer === 'client',
preTransformRequests: preTransformRequest ?? consumer === 'client',
createEnvironment:
environmentName === 'client'
? defaultCreateClientDevEnvironment
Expand Down Expand Up @@ -782,6 +783,7 @@ function resolveEnvironmentOptions(
// Backward compatibility
skipSsrTransform?: boolean,
isSsrTargetWebworkerSet?: boolean,
preTransformRequests?: boolean,
): ResolvedEnvironmentOptions {
const isClientEnvironment = environmentName === 'client'
const consumer =
Expand Down Expand Up @@ -814,6 +816,7 @@ function resolveEnvironmentOptions(
environmentName,
consumer,
skipSsrTransform,
preTransformRequests,
),
build: resolveBuildEnvironmentOptions(
options.build ?? {},
Expand Down Expand Up @@ -1212,6 +1215,7 @@ export async function resolveConfig(
environmentName,
config.experimental?.skipSsrTransform,
config.ssr?.target === 'webworker',
config.server?.preTransformRequests,
)
}

Expand Down

0 comments on commit 12aaa58

Please sign in to comment.