From 89b4e2ba469e1228e762e6ce8fb2abe5b91f3121 Mon Sep 17 00:00:00 2001 From: Cubelrti Date: Tue, 7 Jun 2022 19:39:07 +0800 Subject: [PATCH] fix(vite): keep the sequence of cssPlugins as is to prevent parallel issue when transforming (#1065) --- packages/vite/src/modes/global/build.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/modes/global/build.ts b/packages/vite/src/modes/global/build.ts index 37238409e1..652de63aa4 100644 --- a/packages/vite/src/modes/global/build.ts +++ b/packages/vite/src/modes/global/build.ts @@ -16,17 +16,17 @@ export function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, fi const vfsLayerMap = new Map() const layerImporterMap = new Map() let tasks: Promise[] = [] - let cssPostPlugin: Plugin | undefined - let cssPlugin: Plugin | undefined + let cssPostPlugins: Plugin[] = [] + let cssPlugins: Plugin[] = [] async function transformCSS(css: string, id: string) { const { postcss = true, } = await getConfig() - if (!cssPlugin || !postcss) + if (!cssPlugins.length || !postcss) return css // @ts-expect-error no this context - const result = await cssPlugin.transform(css, id) + const result = await cssPlugins.shift().transform(css, id) if (!result) return css if (typeof result === 'string') @@ -81,14 +81,14 @@ export function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, fi } }, async configResolved(config) { - cssPostPlugin = config.plugins.find(i => i.name === 'vite:css-post') - cssPlugin = config.plugins.find(i => i.name === 'vite:css') + cssPostPlugins.push(config.plugins.find(i => i.name === 'vite:css-post')) + cssPlugins.push(config.plugins.find(i => i.name === 'vite:css')) await ready }, // we inject a hash to chunk before the dist hash calculation to make sure // the hash is different when unocss changes async renderChunk(_, chunk) { - if (!cssPostPlugin) + if (!cssPostPlugins.length) return null const chunks = Object.keys(chunk.modules).filter(i => modules.has(i)) @@ -110,7 +110,7 @@ export function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, fi const hash = getHash(css) // @ts-expect-error no this context - await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId) + await cssPostPlugins.shift().transform(getHashPlaceholder(hash), fakeCssId) // fool the css plugin to generate the css in corresponding chunk chunk.modules[fakeCssId] = { code: null,