diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b2465d4a1d45ba..9c530f9cfbf9b2 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -682,11 +682,17 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `var ${style} = document.createElement('style');` + `${style}.textContent = ${cssString};` + `document.head.appendChild(${style});` + let injectionPoint const wrapIdx = code.indexOf('System.register') - const executeFnStart = - code.indexOf('{', code.indexOf('execute:', wrapIdx)) + 1 + if (wrapIdx >= 0) { + const executeFnStart = code.indexOf('execute:', wrapIdx) + injectionPoint = code.indexOf('{', executeFnStart) + 1 + } else { + const insertMark = "'use strict';" + injectionPoint = code.indexOf(insertMark) + insertMark.length + } const s = new MagicString(code) - s.appendRight(executeFnStart, injectCode) + s.appendRight(injectionPoint, injectCode) if (config.build.sourcemap) { // resolve public URL from CSS paths, we need to use absolute paths return {