import path from 'path' ; import TerserPlugin from 'terser-webpack-plugin' ; import { Configuration } from 'webpack' ; import { packageList , PackageItem } from './packagesForWP' ; function createBatchConfig ( list ) { return list . map ( ( l ) => { const entryBase = { } ; entryBase [ l . name ] = [ `./packages/${ l . dest }/dist/index.js` ] ; const batchBaseConfig = { entry : entryBase , mode : 'production' , module : { rules : [ { test : /\.js$/ , } , ] , } , devtool : 'source-map' , resolve : { symlinks : true , extensions : [ '.js' ] , } , } ; const batchClientConfig = { ... batchBaseConfig , optimization : { minimize : true , minimizer : [ new TerserPlugin ( { terserOptions : { ecma : 6 , compress : true , mangle : true , toplevel : false , output : { beautify : false , comments : false , } , } , parallel : true , sourceMap : true , } ) , ] , } , output : { libraryTarget : 'umd' , library : `${ l . name }` , filename : `${ l . name }.browser.js` , path : path . join ( __dirname , '../../' , 'dist' ) , } , } ; return [ batchBaseConfig , batchClientConfig ] ; } ) ; } function reduceDimension ( arr ) { return Array . prototype . concat . apply ( [ ] , arr ) ; } const batch = reduceDimension ( createBatchConfig ( packageList ) ) ; export default batch ;