2024-02-21 00:17:36 +00:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const path = require('path');
|
2024-02-17 23:27:52 +00:00
|
|
|
|
2024-02-21 00:17:36 +00:00
|
|
|
module.exports = (env) => {
|
|
|
|
|
|
|
|
const isDev = env.mode === 'development';
|
|
|
|
|
|
|
|
const cssLoader = {
|
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
modules: {
|
|
|
|
localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64:8]'
|
|
|
|
},
|
|
|
|
},
|
2024-02-17 23:27:52 +00:00
|
|
|
}
|
2024-02-21 00:17:36 +00:00
|
|
|
|
|
|
|
const config = {
|
|
|
|
mode: env.mode ?? 'development',
|
2024-02-26 17:00:45 +00:00
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
maxEntrypointSize: 512000,
|
|
|
|
maxAssetSize: 512000
|
|
|
|
},
|
2024-02-21 00:17:36 +00:00
|
|
|
entry: './src/index.js',
|
|
|
|
output: {
|
2024-02-26 17:00:45 +00:00
|
|
|
// filename: '[name].[contenthash].js',
|
|
|
|
filename: 'bundle.js',
|
|
|
|
publicPath: '/',
|
2024-02-21 00:17:36 +00:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
|
clean: true
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({template: path.resolve(__dirname, 'public', 'index.html')}),
|
|
|
|
isDev ? undefined : new MiniCssExtractPlugin({
|
|
|
|
filename: 'css/[name].[contenthash:8].css',
|
|
|
|
chunkFilename: 'css/[name].[contenthash:8].css'
|
|
|
|
})
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(scss|css)$/,
|
|
|
|
use: [
|
|
|
|
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
|
|
cssLoader,
|
|
|
|
'sass-loader'
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: "babel-loader",
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
'@babel/preset-env',
|
|
|
|
'@babel/preset-react'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
devServer: {
|
|
|
|
port: env.port ?? 3000,
|
|
|
|
open: true,
|
|
|
|
historyApiFallback: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return config
|
2024-02-17 23:27:52 +00:00
|
|
|
}
|