const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const webpack = require('webpack'); const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); require('dotenv').config(); module.exports = { mode: process.env.NODE_ENV || 'development', entry: './client/src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/', }, cache: { type: 'filesystem', buildDependencies: { config: [__filename], }, cacheDirectory: path.resolve(__dirname, 'node_modules/.cache/webpack'), }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/preset-react'], plugins: [ process.env.NODE_ENV === 'development' && require.resolve('react-refresh/babel') ].filter(Boolean), }, }, }, { test: /\.css$/, use: ['style-loader', 'css-loader'], }, ], }, plugins: [ new HtmlWebpackPlugin({ template: './client/public/index.html', templateParameters: { REACT_APP_GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, }, }), new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'), REACT_APP_GOOGLE_CLIENT_ID: JSON.stringify(process.env.GOOGLE_CLIENT_ID), }, }), ...(process.env.NODE_ENV === 'development' ? [new ReactRefreshWebpackPlugin()] : []), ], devServer: { static: { directory: path.join(__dirname, 'client/public'), }, compress: true, port: 5001, hot: true, historyApiFallback: true, allowedHosts: 'all', host: '0.0.0.0', client: { webSocketURL: 'auto://0.0.0.0:0/ws', }, headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS', 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization', }, proxy: { '/api': { target: 'http://localhost:5500', changeOrigin: true, }, }, }, watchOptions: { ignored: /node_modules/, aggregateTimeout: 300, poll: false, }, snapshot: { managedPaths: [path.resolve(__dirname, 'node_modules')], immutablePaths: [], buildDependencies: { hash: true, timestamp: true, }, module: { timestamp: true, hash: true, }, resolve: { timestamp: true, hash: true, }, resolveBuildDependencies: { timestamp: true, hash: true, }, }, resolve: { extensions: ['.js', '.jsx'], }, };