const path = require('path'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const env = process.env.NODE_ENV; const prodPlugins = env === 'production' ? [ new UglifyJsPlugin({ sourceMap: true, }), ] : []; module.exports = { entry: './src/transport.ts', output: { filename: env === 'production' ? '[name].min.js' : '[name].js', path: path.resolve(__dirname, 'dist'), }, mode: env === 'production' ? 'production' : 'development', module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: [ '@babel/preset-env', ], plugins: [ '@babel/proposal-class-properties', '@babel/proposal-object-rest-spread', ], cacheDirectory: env === 'development', }, }, }, { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/, }, { test: /\.css$/, use: env === 'production' ? ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader'], }) : ['style-loader', 'css-loader'], }, { test: /\.png$/, use: 'file-loader', }, ], }, resolve: { extensions: ['.tsx', '.ts', '.js'], }, plugins: [ new HtmlWebpackPlugin({ template: path.join(__dirname, 'index.html'), }), new ExtractTextPlugin({ disable: env === 'development', filename: '[name].css', }), ...prodPlugins, ], optimization: { splitChunks: { cacheGroups: { commons: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all', }, }, }, }, devtool: env === 'production' ? 'source-map' : 'cheap-module-eval-source-map', devServer: { contentBase: path.join(__dirname, 'dist'), host: '0.0.0.0', port: 8888, disableHostCheck: true, }, };