From 8184feba29c6a89d58bc4437977d22658e946e0c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 7 Dec 2021 14:34:12 +0800 Subject: [PATCH] feat: expose `ssrTransform` to server (#5983) Co-authored-by: patak --- packages/vite/src/node/server/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 8f922a5471918c..b17180c81d5e64 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -55,6 +55,7 @@ import { rebindErrorStacktrace, ssrRewriteStacktrace } from '../ssr/ssrStacktrace' +import { ssrTransform } from '../ssr/ssrTransform' import { createMissingImporterRegisterFn } from '../optimizer/registerMissing' import { resolveHostname } from '../utils' import { searchForWorkspaceRoot } from './searchRoot' @@ -62,6 +63,7 @@ import { CLIENT_DIR } from '../constants' import { printCommonServerUrls } from '../logger' import { performance } from 'perf_hooks' import { invalidatePackageData } from '../packages' +import { SourceMap } from 'rollup' export { searchForWorkspaceRoot } from './searchRoot' @@ -206,6 +208,15 @@ export interface ViteDevServer { options?: EsbuildTransformOptions, inMap?: object ): Promise + /** + * Transform module code into SSR format. + * @experimental + */ + ssrTransform( + code: string, + inMap: SourceMap | null, + url: string + ): Promise /** * Load a given URL as an instantiated module for SSR. */ @@ -337,6 +348,7 @@ export async function createServer( pluginContainer: container, ws, moduleGraph, + ssrTransform, transformWithEsbuild, transformRequest(url, options) { return transformRequest(url, server, options)