File tree Expand file tree Collapse file tree
packages/esbuild-plugin-lit-css Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,9 +195,15 @@ export function litCssPlugin(options?: LitCSSOptions): Plugin {
195195 Promise . resolve ( { contents, changed : false as boolean } ) ,
196196 ) ) ;
197197
198- // inject tag import at the top if not already present
199- if ( anyRewritten && ! alreadyImported )
200- contents = `import {${ tag } } from '${ specifier } ';\n${ contents } ` ;
198+ // inject tag import at the top, preserving any leading hashbang
199+ if ( anyRewritten && ! alreadyImported ) {
200+ const tagImport = `import {${ tag } } from '${ specifier } ';\n` ;
201+ const hashbangMatch = contents . match ( / ^ # ! [ ^ \n ] * \n / ) ;
202+ if ( hashbangMatch )
203+ contents = hashbangMatch [ 0 ] + tagImport + contents . slice ( hashbangMatch [ 0 ] . length ) ;
204+ else
205+ contents = tagImport + contents ;
206+ }
201207
202208 const ext = extname ( args . path ) ;
203209 const loader = LOADER_MAP [ ext ] ?? 'js' ;
You can’t perform that action at this time.
0 commit comments