Minerva/webpack.config.js

75 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-04-14 09:55:58 +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) => {
2024-04-14 09:55:58 +00:00
const isDev = env.mode === "development";
2024-02-21 00:17:36 +00:00
2024-04-14 09:55:58 +00:00
const cssLoader = {
loader: "css-loader",
options: {
modules: {
localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64:8]",
},
},
};
2024-02-21 00:17:36 +00:00
2024-04-14 09:55:58 +00:00
const config = {
mode: env.mode ?? "development",
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
entry: "./src/index.js",
output: {
// filename: '[name].[contenthash].js',
filename: "bundle.js",
publicPath: "/",
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",
],
2024-02-21 00:17:36 +00:00
},
2024-04-14 09:55:58 +00:00
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
2024-02-21 00:17:36 +00:00
},
2024-04-14 09:55:58 +00:00
],
},
devServer: {
port: env.port ?? 3000,
historyApiFallback: true,
host: "0.0.0.0",
allowedHosts: "all",
},
};
2024-02-21 00:17:36 +00:00
2024-04-14 09:55:58 +00:00
return config;
};