const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const webpack = require('webpack'); require('dotenv').config(); module.exports = { mode: 'production', entry: './client/src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'js/[name].[contenthash].js', chunkFilename: 'js/[name].[contenthash].chunk.js', publicPath: '/', clean: true, // Clean dist folder before build }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/preset-react'], }, }, }, { 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 || 'your_google_client_id_here', }, minify: { removeComments: true, collapseWhitespace: true, removeRedundantAttributes: true, useShortDoctype: true, removeEmptyAttributes: true, removeStyleLinkTypeAttributes: true, keepClosingSlash: true, minifyJS: true, minifyCSS: true, minifyURLs: true, }, }), new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production'), REACT_APP_GOOGLE_CLIENT_ID: JSON.stringify(process.env.GOOGLE_CLIENT_ID), }, }), ], optimization: { splitChunks: { chunks: 'all', cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all', }, }, }, }, resolve: { extensions: ['.js', '.jsx'], }, performance: { maxAssetSize: 512000, maxEntrypointSize: 512000, }, };