diff --git a/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts b/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts index 9a350a46bee5a2..6591ecee8b9876 100644 --- a/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts @@ -1,6 +1,10 @@ import { describe, expect, test } from 'vitest' import type { ResolvedConfig, UserConfig } from '../../config' -import { resolveEsbuildTranspileOptions } from '../../plugins/esbuild' +import { + ESBuildTransformResult, + resolveEsbuildTranspileOptions, + transformWithEsbuild +} from '../../plugins/esbuild' describe('resolveEsbuildTranspileOptions', () => { test('resolve default', () => { @@ -237,6 +241,16 @@ describe('resolveEsbuildTranspileOptions', () => { }) }) +describe('transformWithEsbuild', () => { + test('not throw on inline sourcemap', async () => { + const result = await transformWithEsbuild(`const foo = 'bar'`, '', { + sourcemap: 'inline' + }) + expect(result?.code).toBeTruthy() + expect(result?.map).toBeTruthy() + }) +}) + /** * Helper for `resolveEsbuildTranspileOptions` to created resolved config with types. * Note: The function only uses `build.target`, `build.minify` and `esbuild` options. diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 129ec41abca7e0..d7844a0f1b3f63 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -145,9 +145,10 @@ export async function transformWithEsbuild( inMap as RawSourceMap ]) as SourceMap } else { - map = resolvedOptions.sourcemap - ? JSON.parse(result.map) - : { mappings: '' } + map = + resolvedOptions.sourcemap && resolvedOptions.sourcemap !== 'inline' + ? JSON.parse(result.map) + : { mappings: '' } } if (Array.isArray(map.sources)) { map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))