File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,12 +13,29 @@ import devtoolsJson from 'vite-plugin-devtools-json';
1313import mkcert from 'vite-plugin-mkcert' ;
1414
1515function jsBannerPlugin ( banner : string ) : Plugin {
16+ // Matches preserved/legal comment markers that OXC's minifier strips when
17+ // `output.comments.legal === false`: `/*!` starts, plus `@license`,
18+ // `@preserve`, and `@cc_on` JSDoc annotations.
19+ const LEGAL_COMMENT_RE = / \/ \* ! | @ (?: l i c e n s e | p r e s e r v e | c c _ o n ) \b / ;
20+ const modulesWithLegal = new Set < string > ( ) ;
21+
1622 return {
1723 name : 'js-banner' ,
1824 enforce : 'post' ,
25+ buildStart ( ) {
26+ modulesWithLegal . clear ( ) ;
27+ } ,
28+ transform ( code , id ) {
29+ if ( LEGAL_COMMENT_RE . test ( code ) ) {
30+ modulesWithLegal . add ( id ) ;
31+ }
32+ return null ;
33+ } ,
1934 generateBundle ( _ , bundle ) {
2035 for ( const chunk of Object . values ( bundle ) ) {
21- if ( chunk . type === 'chunk' ) {
36+ if ( chunk . type !== 'chunk' ) continue ;
37+ const hasLegal = Object . keys ( chunk . modules ) . some ( ( id ) => modulesWithLegal . has ( id ) ) ;
38+ if ( hasLegal ) {
2239 chunk . code = banner + '\n' + chunk . code ;
2340 }
2441 }
You can’t perform that action at this time.
0 commit comments