decla-red/frontend/webpack.config.js
Andras Schmelczer 93a7fe01ab
All checks were successful
Build & deploy / Build & deploy website (push) Successful in 32s
Build & deploy / Build & publish server image (push) Successful in 1m2s
Improve netcode and simplify (#4)
- Simplify the logic wherever possible to remove overengineering and simplify the netcode
- Actually improve the netcode
- The new lines are mainly the package locks and tests

Reviewed-on: https://home.schmelczer.dev/git/andras/decla-red/pulls/4
2026-09-15 07:57:57 +01:00

121 lines
3.1 KiB
JavaScript

const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default;
const Sass = require('sass');
module.exports = (env, argv) => {
const isProduction = argv.mode !== 'development';
return {
entry: {
main: path.resolve(__dirname, 'src/index.ts'),
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
host: '0.0.0.0',
allowedHosts: 'all',
},
watchOptions: {
poll: true,
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new CopyWebpackPlugin({
patterns: [{ from: 'static/*.svg', to: 'static/[name][ext]' }],
}),
...(isProduction ? [new HTMLInlineCSSWebpackPlugin()] : []),
],
optimization: {
minimizer: [
new TerserJSPlugin({
exclude: /node_modules/,
// The serialization protocol keys on class names.
terserOptions: {
keep_classnames: true,
},
}),
],
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.scss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: Sass,
},
},
],
},
{
test: /\.svg$/,
type: 'asset/inline',
},
{
// No leading slash in `name`: with publicPath 'auto' it doubles the slash.
oneOf: [
{
test: /og-image\.png$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
{
test: /\.ico$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
{
test: /\.(mp3|png)$/,
use: {
loader: 'file-loader',
options: {
name: 'static/[name].[ext]',
},
},
},
],
},
],
},
resolve: {
// Shared physics and rendering must use the same matrix array type as index.ts.
alias: { 'gl-matrix': path.resolve(__dirname, 'node_modules/gl-matrix') },
extensions: ['.ts', '.js', '.json'],
},
};
};