@@ -107,6 +107,7 @@ import {
107
107
} from './asset'
108
108
import type { ESBuildOptions } from './esbuild'
109
109
import { getChunkOriginalFileName } from './manifest'
110
+ import { IIFE_BEGIN_RE , UMD_BEGIN_RE } from './oxc'
110
111
111
112
const decoder = new TextDecoder ( )
112
113
// const debug = createDebugger('vite:css')
@@ -915,22 +916,23 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
915
916
`var ${ style } = document.createElement('style');` +
916
917
`${ style } .textContent = ${ cssString } ;` +
917
918
`document.head.appendChild(${ style } );`
918
- let injectionPoint
919
- const wrapIdx = code . indexOf ( 'System.register ')
920
- const singleQuoteUseStrict = `'use strict';`
921
- const doubleQuoteUseStrict = `"use strict";`
922
- if ( wrapIdx >= 0 ) {
923
- const executeFnStart = code . indexOf ( 'execute:' , wrapIdx )
924
- injectionPoint = code . indexOf ( '{ ' , executeFnStart ) + 1
925
- } else if ( code . includes ( singleQuoteUseStrict ) ) {
926
- injectionPoint =
927
- code . indexOf ( singleQuoteUseStrict ) + singleQuoteUseStrict . length
928
- } else if ( code . includes ( doubleQuoteUseStrict ) ) {
929
- injectionPoint =
930
- code . indexOf ( doubleQuoteUseStrict ) + doubleQuoteUseStrict . length
931
- } else {
932
- throw new Error ( 'Injection point for inlined CSS not found' )
919
+
920
+ if ( opts . format === 'app ')
921
+ this . error ( 'format: "app" is not supported' )
922
+ // TODO: system js support
923
+ // const wrapIdx = code.indexOf('System.register')
924
+ // if (wrapIdx >= 0) {
925
+ // const executeFnStart = code.indexOf('execute: ', wrapIdx)
926
+ // injectionPoint = code.indexOf('{', executeFnStart) + 1
927
+ // }
928
+ const m = (
929
+ opts . format === 'iife' ? IIFE_BEGIN_RE : UMD_BEGIN_RE
930
+ ) . exec ( code )
931
+ if ( ! m ) {
932
+ this . error ( 'Injection point for inlined CSS not found' )
933
+ return
933
934
}
935
+ const injectionPoint = m . index + m [ 0 ] . length
934
936
s ||= new MagicString ( code )
935
937
s . appendRight ( injectionPoint , injectCode )
936
938
}
0 commit comments