Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): style insert order for UMD builds (fix #13668) #13669

Merged
merged 3 commits into from Jul 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/vite/src/node/plugins/css.ts
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