const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const path = require('path')

// Check if HTTPS mode is enabled via environment variable
const useHttps = process.env.HTTPS === 'true'

module.exports = merge(common, {
    mode: 'development',
    devtool: 'eval-source-map',
    watchOptions: {
        ignored: /node_modules/,
    },
    devServer: {
        allowedHosts: 'all',
        hot: false,
        liveReload: false,
        open: false,
        // Enable HTTPS with self-signed certificate when HTTPS=true
        ...(useHttps && { server: 'https' }),
        static: [
            {
                directory: path.join(__dirname, './build'),
                watch: false,
            },
            {
                directory: path.join(__dirname, './public'),
                publicPath: '/',
                watch: false,
            },
        ],
        watchFiles: [],
        client: {
            progress: true,
            overlay: {
                errors: true,
                warnings: false,
            },
        },
        devMiddleware: {
            writeToDisk: true,
        },
        compress: true,
        port: 8080,
    },
})
