import * as dotenv from "dotenv" ; import { Application } from "express" ; import * as HtmlPlugin from "html-webpack-plugin" ; import { createProxyMiddleware } from "http-proxy-middleware" ; import * as path from "path" ; import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin" ; import { Configuration , NoEmitOnErrorsPlugin } from "webpack" ; param env param args return export default ( _env , args ) => { const { parsed : env } = dotenv . config ( ) ; return { mode : args . mode , entry : [ "src" ] , module : { rules : [ { test : /\.tsx?$/ , use : [ "babel-loader" , { loader : "ts-loader" , options : { transpileOnly : true , experimentalWatchApi : true , compilerOptions : { noUnusedLocals : args . mode === "production" , noUnusedParameters : args . mode === "production" , module : "es2015" } } } ] , exclude : /\/node_modules\// } , { test : /\.html$/ , use : [ { loader : "string-replace-loader" , options : { multiple : Object . keys ( args . mode === "development" ? env ! : { } ) . reduce ( ( variables , key ) => ( [ ... variables , { search : `\\\${${ key . toLowerCase ( ) }}` , replace : env ! [ key ] , flags : "g" } ] ) , [ ] ) } } , { loader : "html-loader" , options : { minimize : true } } ] } ] } , output : { path : path . resolve ( __dirname , "dist" ) , pathinfo : false , filename : "[name]" + ( args . mode === "production" ? ".[chunkhash]" : "" ) + ".bundle.js" } , plugins : [ new NoEmitOnErrorsPlugin ( ) , new HtmlPlugin ( { template : "src/index.html" , filename : "index.html" } ) ] , resolve : { modules : [ __dirname , "node_modules" ] , extensions : [ ".ts" , ".tsx" , ".js" , ".json" ] , plugins : [ new TsconfigPathsPlugin ( ) ] } , devtool : "source-map" , devServer : { contentBase : "/dist/" , historyApiFallback : true , hot : true , port : 9090 , stats : { warningsFilter : /export .* was not found in/ } as any , before : ( app ) => app . use ( "/identity" , createProxyMiddleware ( { target : "http://localhost:9091" , changeOrigin : true } ) as any ) } , optimization : { splitChunks : { cacheGroups : { commons : { chunks : "initial" , minChunks : 2 , maxInitialRequests : 5 , minSize : 0 } , vendor : { test : /node_modules/ , chunks : "initial" , name : "vendor" , priority : 10 , enforce : true } } } } , stats : { warningsFilter : /export .* was not found in/ } , watchOptions : { ignored : /\/node_modules\// } } ; } ;