From e444375d34db1e1902f06ab223e51d2d63cd10de Mon Sep 17 00:00:00 2001 From: lsdsjy Date: Mon, 22 May 2023 17:21:03 +0800 Subject: [PATCH] fix(legacy): style insert order (#13266) Co-authored-by: sapphi-red --- packages/vite/src/node/plugins/css.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 9ff54241a9e724..21cb0b77b91006 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -636,10 +636,10 @@ 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 {