From b59c21f26ab521959eb0e49933c196f47f4e191f Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Thu, 20 Jun 2024 18:36:15 +0200 Subject: [PATCH] fix(CSSEntryPoints): name CSS entries as original entries Signed-off-by: Grigorii K. Shartsev --- lib/plugins/CSSEntryPoints.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/plugins/CSSEntryPoints.ts b/lib/plugins/CSSEntryPoints.ts index 015ba829..d3a2c9ea 100644 --- a/lib/plugins/CSSEntryPoints.ts +++ b/lib/plugins/CSSEntryPoints.ts @@ -8,7 +8,7 @@ import type { OutputOptions, PreRenderedAsset } from 'rollup' import type { Plugin } from 'vite' -import { basename, dirname, join, normalize } from 'path' +import { basename, dirname, join, normalize, extname } from 'path' interface CSSEntryPointsPluginOptions { /** @@ -97,8 +97,13 @@ export function CSSEntryPointsPlugin(options?: CSSEntryPointsPluginOptions) { .map((css) => `@import './${basename(css)}';`) .join('\n') - const cssName = `${chunk.name}.css` + // Name new CSS entry same as the entry + const entryName = basename(chunk.fileName).slice(0, -1 * extname(chunk.fileName).length) + const cssName = `${entryName}.css` + + // Keep original path const path = dirname(typeof options.assetFileNames === 'string' ? options.assetFileNames : options.assetFileNames({ type: 'asset', source: '', name: 'name.css' })) + this.emitFile({ type: 'asset', name: `\0${cssName}`, @@ -107,6 +112,6 @@ export function CSSEntryPointsPlugin(options?: CSSEntryPointsPluginOptions) { source: `/* extracted by css-entry-points-plugin */\n${source}`, }) } - } + }, } as Plugin }