Skip to content

Commit

Permalink
feat: option to disable pre-transform (vitejs#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored and aleclarson committed Jan 7, 2022
1 parent c5777c7 commit 1b23c9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Expand Up @@ -544,7 +544,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
)

// pre-transform known direct imports
if (staticImportedUrls.size) {
if (config.server.preTransformRequests && staticImportedUrls.size) {
staticImportedUrls.forEach((url) => {
server.transformRequest(unwrapId(removeImportQuery(url)), { ssr })
})
Expand Down
14 changes: 12 additions & 2 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -114,6 +114,13 @@ export interface ServerOptions extends CommonServerOptions {
* @default true
*/
bindShortcuts?: boolean
/**
* Pre-transform known direct imports
*
* @experimental this option is experimental and might be changed in the future
* @default true
*/
preTransformRequests?: boolean
}

export interface ResolvedServerOptions extends ServerOptions {
Expand Down Expand Up @@ -702,7 +709,10 @@ export function resolveServerOptions(
root: string,
raw?: ServerOptions
): ResolvedServerOptions {
const server = raw || {}
const server: ResolvedServerOptions = {
preTransformRequests: true,
...(raw as ResolvedServerOptions)
}
let allowDirs = server.fs?.allow

if (!allowDirs) {
Expand All @@ -723,7 +733,7 @@ export function resolveServerOptions(
allow: allowDirs
}
server.static = resolveStaticOptions(server)
return server as ResolvedServerOptions
return server
}

async function restartServer(server: ViteDevServer) {
Expand Down

0 comments on commit 1b23c9f

Please sign in to comment.