perfect-postcode/frontend/webpack.config.js
2026-02-07 13:25:37 +00:00

73 lines
1.8 KiB
JavaScript

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
return {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
clean: true,
// Dev needs '/' for HMR WebSocket; prod uses '' for relative paths through proxies
publicPath: isProduction ? '' : '/',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
['@babel/preset-react', { runtime: 'automatic' }],
'@babel/preset-typescript',
],
plugins: isProduction ? [] : ['react-refresh/babel'],
},
},
},
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'postcss-loader',
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
}),
...(isProduction
? [new MiniCssExtractPlugin()]
: [new ReactRefreshWebpackPlugin()]),
],
devServer: {
port: 3000,
allowedHosts: 'all',
historyApiFallback: {
index: 'index.html',
},
hot: true,
liveReload: true,
proxy: [
{
context: ['/api'],
target: 'http://localhost:8001',
},
],
},
};
};