From 91eadffb50965ed49505a6e56711030452977529 Mon Sep 17 00:00:00 2001 From: Jono Mingard Date: Fri, 14 Jul 2023 09:57:47 +0900 Subject: [PATCH] fix(build): inject css below use strict directive --- packages/vite/src/node/plugins/css.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index cf21b1a974e42a..9c530f9cfbf9b2 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -682,10 +682,15 @@ 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 = - wrapIdx >= 0 ? code.indexOf('execute:', wrapIdx) : 0 - const injectionPoint = code.indexOf('{', executeFnStart) + 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(injectionPoint, injectCode) if (config.build.sourcemap) {