Open History to see the last commit
1import path from 'path'
2import { fileURLToPath } from 'url'
3import HtmlWebpackPlugin from 'html-webpack-plugin'
4import { tanstackRouter } from '@tanstack/router-plugin/webpack'
5β
6const __dirname = fileURLToPath(new URL('.', import.meta.url))
7β
8/** @type import('webpack').Configuration */
9export default ({ WEBPACK_SERVE }) => ({
10 target: 'web',
11 mode: WEBPACK_SERVE ? 'development' : 'production',
12 entry: path.resolve(__dirname, './src/index.tsx'),
13 output: {
14 path: path.resolve(__dirname, './dist'),
15 filename: '[name].bundle.js',
16 publicPath: '/',
17 },
18 resolve: {
19 extensions: ['.ts', '.tsx', '.js', '.jsx'],
20 },
21 plugins: [
22 new HtmlWebpackPlugin({
23 template: path.resolve(__dirname, './public/index.html'),
24 filename: 'index.html',
25 }),
26 tanstackRouter({
27 target: 'react',
28 autoCodeSplitting: true,
29 codeSplittingOptions: { addHmr: Boolean(WEBPACK_SERVE) },
30 }),
31 ],
32 module: {
33 rules: [
34 {
35 test: /\.tsx?$/,
36 exclude: /(node_modules)/,
37 use: { loader: 'swc-loader' },
38 },
39 ],
40 },
41 devServer: {
42 open: true,
43 hot: true,
44 historyApiFallback: {
45 rewrites: [{ from: /./, to: '/index.html' }],
46 },
47 static: ['public'],
48 },
49})