-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
134 lines (121 loc) · 4.27 KB
/
webpack.config.js
File metadata and controls
134 lines (121 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// @ts-check
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
/** @param {Record<string, unknown>} _env @param {{ mode: string }} argv */
module.exports = (_env, argv) => {
const isProd = argv.mode === 'production';
return {
entry: './src/main.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
// Content-hash filenames in production for long-term caching.
filename: isProd ? '[name].[contenthash].js' : '[name].js',
chunkFilename: isProd ? '[name].[contenthash].js' : '[name].js',
// Allow the public path to be overridden via an environment variable.
// Used in CI to set the correct base path for GitHub Pages deployments
// (e.g. PUBLIC_PATH=/claude-code-todo-list/). Defaults to / for local dev.
publicPath: process.env.PUBLIC_PATH || '/',
clean: true,
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
// TypeScript / JSX — transpiled by Babel; type-checking is handled
// separately by ForkTsCheckerWebpackPlugin in parallel.
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: 'defaults' }],
['@babel/preset-react', { runtime: 'automatic' }],
'@babel/preset-typescript',
],
},
},
},
// CSS Modules — scoped styles used by all components.
{
test: /\.module\.css$/,
use: [
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
// Use CommonJS-style exports so the default import resolves
// correctly regardless of how babel-loader handles ES modules.
esModule: false,
modules: {
// Readable class names in dev; hashed in production.
localIdentName: isProd ? '[hash:base64]' : '[local]__[hash:base64:5]',
},
},
},
],
},
// Global CSS (e.g. src/styles/global.css).
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: [
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
{ loader: 'css-loader', options: { esModule: false } },
],
},
],
},
plugins: [
// Injects the bundled scripts into index.html automatically.
new HtmlWebpackPlugin({ template: './index.html' }),
// Runs TypeScript type-checking in a separate worker so it does not
// block the webpack compilation.
new ForkTsCheckerWebpackPlugin(),
// Extract CSS to separate files in production only.
...(isProd ? [new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' })] : []),
],
optimization: isProd
? {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// Strip all console.* calls and debugger statements from
// the production bundle.
drop_console: true,
drop_debugger: true,
},
},
}),
],
splitChunks: {
cacheGroups: {
// Split React + ReactDOM into a separate vendor chunk so it
// can be cached independently from app code.
vendor: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
}
: {},
devServer: {
port: 8080,
hot: true,
// Required for client-side routing (SPA fallback).
historyApiFallback: true,
open: false,
},
// Inline source maps in dev for fast rebuilds; disabled in production.
devtool: isProd ? false : 'eval-source-map',
};
};