import getBaseConfig from './webpack.base.config' ; import { getCwdPath , } from '@/util' ; import { Configuration } from 'webpack' ; const TerserPlugin = require ( "terser-webpack-plugin" ) ; interface IWebpackConfig extends Configuration { entry ? : { app : string ; } ; output ? : { chunkFilename : string ; filename : string ; path : string ; } ; template ? : string ; cssLoader ? : any ; plugins ? : any ; } export const getProConfig = ( config ) : Configuration => { const { entry , template , output , cssLoader , plugins , ... rest } = config ; return { ... getBaseConfig ( { mode : 'production' , entry : { app : getCwdPath ( entry ?. app || './src/index.js' ) } , output : { chunkFilename : output ?. chunkFilename || 'static/js/[name].[contenthash].js' , filename : output ?. filename || 'static/js/[name].[contenthash].js' , path : getCwdPath ( output ?. path || './dist' ) , } , template : getCwdPath ( template || 'public/index.html' ) , cssLoader , plugins } ) , optimization : { minimize : true , minimizer : [ new TerserPlugin ( { parallel : true , test : /\.js(\?.*)?$/i , include : getCwdPath ( 'src' ) , exclude : /node_modules/ } ) , ] , runtimeChunk : { name : ( entrypoint ) => `runtime-${ entrypoint . name }` , } , splitChunks : { cacheGroups : { commons : { test : /[\\/]node_modules[\\/]/ , chunks : 'all' , priority : 10 , enforce : true } , } , } , } , ... rest , } ; } ;