Skip to content

Commit 0dc2439

Browse files
antfualeclarson
authored andcommitted
feat: option to disable pre-transform (vitejs#6309)
1 parent b60d417 commit 0dc2439

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/vite/src/node/plugins/importAnalysis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
544544
)
545545

546546
// pre-transform known direct imports
547-
if (staticImportedUrls.size) {
547+
if (config.server.preTransformRequests && staticImportedUrls.size) {
548548
staticImportedUrls.forEach((url) => {
549549
server.transformRequest(unwrapId(removeImportQuery(url)), { ssr })
550550
})

packages/vite/src/node/server/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export interface ServerOptions extends CommonServerOptions {
114114
* @default true
115115
*/
116116
bindShortcuts?: boolean
117+
/**
118+
* Pre-transform known direct imports
119+
*
120+
* @experimental this option is experimental and might be changed in the future
121+
* @default true
122+
*/
123+
preTransformRequests?: boolean
117124
}
118125

119126
export interface ResolvedServerOptions extends ServerOptions {
@@ -702,7 +709,10 @@ export function resolveServerOptions(
702709
root: string,
703710
raw?: ServerOptions
704711
): ResolvedServerOptions {
705-
const server = raw || {}
712+
const server: ResolvedServerOptions = {
713+
preTransformRequests: true,
714+
...(raw as ResolvedServerOptions)
715+
}
706716
let allowDirs = server.fs?.allow
707717

708718
if (!allowDirs) {
@@ -723,7 +733,7 @@ export function resolveServerOptions(
723733
allow: allowDirs
724734
}
725735
server.static = resolveStaticOptions(server)
726-
return server as ResolvedServerOptions
736+
return server
727737
}
728738

729739
async function restartServer(server: ViteDevServer) {

0 commit comments

Comments
 (0)