import { Compiler } from "webpack" ; import { ConcatSource } from "webpack-sources" ; export class AutoJSUI { constructor ( private UIScriptList ) { } apply ( compiler ) { compiler . hooks . compilation . tap ( 'AutoJSUI' , ( compilation , normalModuleFactory ) => { compilation . hooks . optimizeChunkAssets . tap ( 'AutoJSUI' , ( chunks ) => { for ( const chunk of chunks ) { if ( chunk . canBeInitial ( ) ) { if ( this . UIScriptList . includes ( chunk . name ) ) { chunk . files . forEach ( file => { compilation . assets [ file ] = new ConcatSource ( '"ui";' , '\n' , compilation . assets [ file ] ) ; } ) ; } } } } ) ; } ) ; } }