Skip to content

Commit

Permalink
fix(build): style insert order for UMD builds (fix #13668) (#13669)
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-koan committed Jul 14, 2023
1 parent 435d4e7 commit 49a1b99
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49a1b99

Please sign in to comment.