From b1209bbfb28e430f4032df4e4cdd90f4d3376ed1 Mon Sep 17 00:00:00 2001 From: sun0day Date: Tue, 5 Sep 2023 10:45:43 +0800 Subject: [PATCH] fix(css): remove pure css chunk sourcemap --- packages/vite/src/node/plugins/css.ts | 1 + .../__tests__/lib-entry/lib-entry.spec.ts | 8 ++++++++ playground/css-sourcemap/index.js | 1 + playground/css-sourcemap/vite.config-lib-entry.js | 13 +++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 playground/css-sourcemap/__tests__/lib-entry/lib-entry.spec.ts create mode 100644 playground/css-sourcemap/index.js create mode 100644 playground/css-sourcemap/vite.config-lib-entry.js diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index a9fcf4a50c13aa..da1ef1fcfecefe 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -786,6 +786,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { pureCssChunkNames.forEach((fileName) => { removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk) delete bundle[fileName] + delete bundle[`${fileName}.map`] }) } diff --git a/playground/css-sourcemap/__tests__/lib-entry/lib-entry.spec.ts b/playground/css-sourcemap/__tests__/lib-entry/lib-entry.spec.ts new file mode 100644 index 00000000000000..d2fa5f7d2c31e7 --- /dev/null +++ b/playground/css-sourcemap/__tests__/lib-entry/lib-entry.spec.ts @@ -0,0 +1,8 @@ +import { describe, expect, test } from 'vitest' +import { findAssetFile, isBuild } from '~utils' + +describe.runIf(isBuild)('css lib entry', () => { + test('remove useless js sourcemap', async () => { + expect(findAssetFile('linked.js.map', 'lib-entry', './')).toBe('') + }) +}) diff --git a/playground/css-sourcemap/index.js b/playground/css-sourcemap/index.js new file mode 100644 index 00000000000000..c05f09558ddaf0 --- /dev/null +++ b/playground/css-sourcemap/index.js @@ -0,0 +1 @@ +export default 'hello' diff --git a/playground/css-sourcemap/vite.config-lib-entry.js b/playground/css-sourcemap/vite.config-lib-entry.js new file mode 100644 index 00000000000000..600b7414a48b75 --- /dev/null +++ b/playground/css-sourcemap/vite.config-lib-entry.js @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + build: { + cssCodeSplit: true, + sourcemap: true, + outDir: 'dist/lib-entry', + lib: { + entry: ['./index.js', './linked.css'], + formats: ['es'], + }, + }, +})