From 90e47a2be8298ba9efd50518f1ae6db424d26980 Mon Sep 17 00:00:00 2001 From: underfin Date: Thu, 12 Dec 2024 17:19:46 +0800 Subject: [PATCH] fix: insert inline css --- packages/vite/src/node/plugins/css.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 294cd5104ac768..6939a7a5b6b069 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -880,12 +880,21 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin { `document.head.appendChild(${style});` let injectionPoint const wrapIdx = code.indexOf('System.register') + const singleQuotesUseStruct = `'use strict';` + const doubleQuotesUseStruct = `"use strict";` if (wrapIdx >= 0) { const executeFnStart = code.indexOf('execute:', wrapIdx) injectionPoint = code.indexOf('{', executeFnStart) + 1 + } else if (code.includes(singleQuotesUseStruct)) { + injectionPoint = + code.indexOf(singleQuotesUseStruct) + + singleQuotesUseStruct.length + } else if (code.includes(doubleQuotesUseStruct)) { + injectionPoint = + code.indexOf(doubleQuotesUseStruct) + + doubleQuotesUseStruct.length } else { - const insertMark = "'use strict';" - injectionPoint = code.indexOf(insertMark) + insertMark.length + throw new Error('Not found injection point for inlined CSS') } s ||= new MagicString(code) s.appendRight(injectionPoint, injectCode)