From 324f569ead2447903a9da86794075ecabaf59702 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Sun, 25 Feb 2024 07:06:11 +0800 Subject: [PATCH] Remove unnecessary enableSourcemap usage (#862) --- .changeset/late-pans-guess.md | 5 +++++ packages/vite-plugin-svelte/src/utils/compile.js | 7 ------- .../vite-plugin-svelte/src/utils/load-raw.js | 16 +++++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 .changeset/late-pans-guess.md diff --git a/.changeset/late-pans-guess.md b/.changeset/late-pans-guess.md new file mode 100644 index 000000000..b031fcc8c --- /dev/null +++ b/.changeset/late-pans-guess.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +Remove unnecessary `enableSourcemap` option usage and prevent passing it in Svelte 5 diff --git a/packages/vite-plugin-svelte/src/utils/compile.js b/packages/vite-plugin-svelte/src/utils/compile.js index 3218a0610..a8017a799 100644 --- a/packages/vite-plugin-svelte/src/utils/compile.js +++ b/packages/vite-plugin-svelte/src/utils/compile.js @@ -71,13 +71,6 @@ export const _createCompileSvelte = (makeHot) => { const hash = `s-${safeBase64Hash(normalizedFilename)}`; compileOptions.cssHash = () => hash; } - if (ssr && compileOptions.enableSourcemap !== false) { - if (typeof compileOptions.enableSourcemap === 'object') { - compileOptions.enableSourcemap.css = false; - } else { - compileOptions.enableSourcemap = { js: true, css: false }; - } - } let preprocessed; let preprocessors = options.preprocess; diff --git a/packages/vite-plugin-svelte/src/utils/load-raw.js b/packages/vite-plugin-svelte/src/utils/load-raw.js index e43ff0dcf..75a697cc7 100644 --- a/packages/vite-plugin-svelte/src/utils/load-raw.js +++ b/packages/vite-plugin-svelte/src/utils/load-raw.js @@ -1,7 +1,7 @@ import fs from 'node:fs'; import { toRollupError } from './error.js'; import { log } from './log.js'; -import { isSvelte4 } from './svelte-version.js'; +import { isSvelte4, isSvelte5 } from './svelte-version.js'; /** * utility function to compile ?raw and ?direct requests in load hook * @@ -27,12 +27,14 @@ export async function loadRaw(svelteRequest, compileSvelte, options) { compilerOptions: { dev: false, css: 'external', - enableSourcemap: query.sourcemap - ? { - js: type === 'script' || type === 'all', - css: type === 'style' || type === 'all' - } - : false, + enableSourcemap: isSvelte5 + ? undefined + : query.sourcemap + ? { + js: type === 'script' || type === 'all', + css: type === 'style' || type === 'all' + } + : false, ...svelteRequest.query.compilerOptions }, hot: false,