Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

webpack.config.js

45 lines1.1 KB

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({ target: 'react', autoCodeSplitting: true }),
27 ],
28 module: {
29 rules: [
30 {
31 test: /\.tsx?$/,
32 exclude: /(node_modules)/,
33 use: { loader: 'swc-loader' },
34 },
35 ],
36 },
37 devServer: {
38 open: true,
39 hot: true,
40 historyApiFallback: {
41 rewrites: [{ from: /./, to: '/index.html' }],
42 },
43 static: ['public'],
44 },
45})