From b390d564e2176294b48cfa8f5300fb51505c2665 Mon Sep 17 00:00:00 2001 From: lsdsjy Date: Fri, 19 May 2023 14:58:02 +0800 Subject: [PATCH 1/2] fix(legacy): style insert order --- packages/vite/src/node/plugins/css.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 9ff54241a9e724..c66d258140b59c 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -636,10 +636,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `${style}.textContent = ${cssString};` + `document.head.appendChild(${style});` const wrapIdx = code.indexOf('System.register') - const insertMark = "'use strict';" - const insertIdx = code.indexOf(insertMark, wrapIdx) + const executeFnStart = code.indexOf('{', code.indexOf('execute:', wrapIdx)) + 1 const s = new MagicString(code) - s.appendLeft(insertIdx + insertMark.length, injectCode) + s.appendRight(executeFnStart, injectCode) if (config.build.sourcemap) { // resolve public URL from CSS paths, we need to use absolute paths return { From aa8a9ed2230a92e1788bc1ccd6d1599ff874e84c Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sun, 21 May 2023 22:10:33 +0900 Subject: [PATCH 2/2] chore: format --- packages/vite/src/node/plugins/css.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c66d258140b59c..21cb0b77b91006 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -636,7 +636,8 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `${style}.textContent = ${cssString};` + `document.head.appendChild(${style});` const wrapIdx = code.indexOf('System.register') - const executeFnStart = code.indexOf('{', code.indexOf('execute:', wrapIdx)) + 1 + const executeFnStart = + code.indexOf('{', code.indexOf('execute:', wrapIdx)) + 1 const s = new MagicString(code) s.appendRight(executeFnStart, injectCode) if (config.build.sourcemap) {