From e781ef33455f40ad0f1e5dbf2e841e00879aeab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Ayg=C3=BCn?= Date: Wed, 18 Jan 2023 20:20:39 +0300 Subject: [PATCH] feat: add experimental option to skip SSR transform (#11411) --- packages/vite/src/node/config.ts | 8 ++++++++ packages/vite/src/node/server/transformRequest.ts | 15 ++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 898f63af090a70..7c5491694b27db 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -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 { diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index f10cfde5ac3b87..fb64c190cce7f6 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -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