import * as path from 'path' ; import gzipSize from 'gzip-size' ; import webpack from 'webpack' ; export interface LambdaFileSizePluginOptions { writeFile ? : boolean ; } export class LambdaFileSizePlugin { public static readonly NAME = 'LambdaFileSizePlugin' ; constructor ( private readonly options ) { } apply ( compiler ) { compiler . hooks . afterEmit . tapPromise ( LambdaFileSizePlugin . NAME , async ( compilation ) : Promise < void > => { await this . outpuzSizes ( compilation . assets ) ; } ) ; } private async outpuzSizes ( assets ) { const assetNames = Object . keys ( assets ) . filter ( ( file ) => path . extname ( file ) === '.js' ) ; const sizes = await Promise . all ( assetNames . map ( ( name ) => gzipSize ( assets [ name ] . source ( ) ) ) ) ; const sizeMap = { } ; assetNames . forEach ( ( name , index ) => { sizeMap [ name ] = sizes [ index ] ; } ) ; console . log ( sizeMap , this . options ) ; } }