Skip to content

Commit

Permalink
feat: option to disable pre-transform (#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 30, 2021
1 parent 0ebeb98 commit 2c14525
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 @@ -566,7 +566,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
)

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

export interface ResolvedServerOptions extends ServerOptions {
Expand Down Expand Up @@ -692,7 +699,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
const deny = server.fs?.deny || ['.env', '.env.*', '*.{crt,pem}']

Expand All @@ -713,7 +723,7 @@ export function resolveServerOptions(
allow: allowDirs,
deny
}
return server as ResolvedServerOptions
return server
}

async function restartServer(server: ViteDevServer) {
Expand Down

0 comments on commit 2c14525

Please sign in to comment.