const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
return {
entry: './web/src/index.tsx',
output: {
path: path.resolve(__dirname, 'build'),
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
clean: true,
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
alias: {
'@': path.resolve(__dirname, 'web/src'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './web/public/index.html',
favicon: './web/public/favicon.ico',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.REACT_APP_API_BASE': JSON.stringify(process.env.REACT_APP_API_BASE || '/rpc'),
}),
],
devServer: {
static: {
directory: path.join(__dirname, 'web/public'),
},
compress: true,
port: 3001,
hot: true,
historyApiFallback: true,
proxy: {
'/rpc': {
target: 'http://localhost:3000',
changeOrigin: true,
},
},
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
devtool: isProduction ? 'source-map' : 'eval-source-map',
};
};