From caa644462571e76aca25a647b9ffa43ce7c340b3 Mon Sep 17 00:00:00 2001 From: Mikhail Avdeev Date: Sat, 1 Jun 2024 18:46:42 +0300 Subject: [PATCH] fix(css): handle lightningcss build minify in Deno --- packages/vite/src/node/plugins/css.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index e4b08ba4b8e22b..3b82ca9f19130c 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -83,6 +83,7 @@ import { import type { ESBuildOptions } from './esbuild' import { getChunkOriginalFileName } from './manifest' +const decoder = new TextDecoder() // const debug = createDebugger('vite:css') export interface CSSOptions { @@ -1808,8 +1809,12 @@ async function minifyCSS( ), ) } + + // NodeJS res.code = Buffer + // Deno res.code = Uint8Array + // For correct decode compiled css need to use TextDecoder // LightningCSS output does not return a linebreak at the end - return code.toString() + (inlined ? '' : '\n') + return decoder.decode(code) + (inlined ? '' : '\n') } try { const { code, warnings } = await transform(css, { @@ -2698,8 +2703,6 @@ function isPreProcessor(lang: any): lang is PreprocessLang { } const importLightningCSS = createCachedImport(() => import('lightningcss')) - -const decoder = new TextDecoder() async function compileLightningCSS( id: string, src: string,