Skip to content

Commit

Permalink
feat: add experimental option to skip SSR transform
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 committed Dec 18, 2022
1 parent 0a07686 commit aaf2f7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
19 changes: 16 additions & 3 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ export interface ExperimentalOptions {
* @default false
*/
hmrPartialAccept?: boolean
/**
* Skips SSR transform to make it easier to use Vite with Node ESM loaders.
* @warning Enabling this will break normal operation of Vite's SSR in development mode.
*
* @experimental
* @default false
*/
skipSsrTransform?: boolean
}

export interface LegacyOptions {
Expand Down Expand Up @@ -462,13 +470,18 @@ export async function resolveConfig(
)

const clientAlias = [
{ find: /^\/?@vite\/env/, replacement: ENV_ENTRY },
{ find: /^\/?@vite\/client/, replacement: CLIENT_ENTRY },
{ find: /^\/?@vite\/env/, replacement: () => ENV_ENTRY },
{ find: /^\/?@vite\/client/, replacement: () => CLIENT_ENTRY },
]

// resolve alias with internal client alias
const resolvedAlias = normalizeAlias(
mergeAlias(clientAlias, config.resolve?.alias || []),
mergeAlias(
// @ts-expect-error because @rollup/plugin-alias' type doesn't allow function
// replacement, but its implementation does work with function values.
clientAlias,
config.resolve?.alias || [],
),
)

const resolveOptions: ResolvedConfig['resolve'] = {
Expand Down
15 changes: 8 additions & 7 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,14 @@ async function loadAndTransform(
}
}

const result = ssr
? await server.ssrTransform(code, map as SourceMap, url, originalCode)
: ({
code,
map,
etag: getEtag(code, { weak: true }),
} as TransformResult)
const result =
ssr && !server.config.experimental.skipSsrTransform
? await server.ssrTransform(code, map as SourceMap, url, originalCode)
: ({
code,
map,
etag: getEtag(code, { weak: true }),
} as TransformResult)

// Only cache the result if the module wasn't invalidated while it was
// being processed, so it is re-processed next time if it is stale
Expand Down

0 comments on commit aaf2f7b

Please sign in to comment.