Skip to content

Commit

Permalink
refactor: use server.ssrTransform (#9769)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Aug 20, 2022
1 parent 01857af commit 246a087
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ export interface ViteDevServer {
ssrTransform(
code: string,
inMap: SourceMap | null,
url: string
url: string,
originalCode?: string
): Promise<TransformResult | null>
/**
* Load a given URL as an instantiated module for SSR.
Expand Down Expand Up @@ -339,8 +340,13 @@ export async function createServer(
ws,
moduleGraph,
resolvedUrls: null, // will be set on listen
ssrTransform(code: string, inMap: SourceMap | null, url: string) {
return ssrTransform(code, inMap, url, code, server.config)
ssrTransform(
code: string,
inMap: SourceMap | null,
url: string,
originalCode = code
) {
return ssrTransform(code, inMap, url, originalCode, server.config)
},
transformRequest(url, options) {
return transformRequest(url, server, options)
Expand Down
9 changes: 1 addition & 8 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
timeFrom
} from '../utils'
import { checkPublicFile } from '../plugins/asset'
import { ssrTransform } from '../ssr/ssrTransform'
import { getDepsOptimizer } from '../optimizer'
import { injectSourcesContent } from './sourcemap'
import { isFileServingAllowed } from './middlewares/static'
Expand Down Expand Up @@ -259,13 +258,7 @@ async function loadAndTransform(
}

const result = ssr
? await ssrTransform(
code,
map as SourceMap,
url,
originalCode,
server.config
)
? await server.ssrTransform(code, map as SourceMap, url, originalCode)
: ({
code,
map,
Expand Down

0 comments on commit 246a087

Please sign in to comment.