Skip to content

Commit ebd8db5

Browse files
authored
fix(css): inline css insert for single quote use strict (#79)
1 parent d97ef9e commit ebd8db5

File tree

1 file changed

+11
-2
lines changed
  • packages/vite/src/node/plugins

1 file changed

+11
-2
lines changed

packages/vite/src/node/plugins/css.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,21 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
880880
`document.head.appendChild(${style});`
881881
let injectionPoint
882882
const wrapIdx = code.indexOf('System.register')
883+
const singleQuotesUseStruct = `'use strict';`
884+
const doubleQuotesUseStruct = `"use strict";`
883885
if (wrapIdx >= 0) {
884886
const executeFnStart = code.indexOf('execute:', wrapIdx)
885887
injectionPoint = code.indexOf('{', executeFnStart) + 1
888+
} else if (code.includes(singleQuotesUseStruct)) {
889+
injectionPoint =
890+
code.indexOf(singleQuotesUseStruct) +
891+
singleQuotesUseStruct.length
892+
} else if (code.includes(doubleQuotesUseStruct)) {
893+
injectionPoint =
894+
code.indexOf(doubleQuotesUseStruct) +
895+
doubleQuotesUseStruct.length
886896
} else {
887-
const insertMark = "'use strict';"
888-
injectionPoint = code.indexOf(insertMark) + insertMark.length
897+
throw new Error('Not found injection point for inlined CSS')
889898
}
890899
s ||= new MagicString(code)
891900
s.appendRight(injectionPoint, injectCode)

0 commit comments

Comments
 (0)