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)