Skip to content

Commit

Permalink
fix: insert inline css
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Dec 12, 2024
1 parent d97ef9e commit 90e47a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 90e47a2

Please sign in to comment.