forked from Tsalmas-Anastasios/react19-wepback-spa-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
66 lines (63 loc) · 2.12 KB
/
Copy pathwebpack.config.js
File metadata and controls
66 lines (63 loc) · 2.12 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
import path from 'node:path';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import Dotenv from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const createWebpackConfig = (environment) => {
return {
entry: './src/index.tsx',
mode: environment.NODE_ENV || 'development',
output: {
filename: 'bundle.[fullhash].js',
path: path.resolve(import.meta.dirname, 'dist'),
publicPath: '/',
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new Dotenv({
safe: true,
}),
],
resolve: {
modules: [import.meta.dirname, 'src', 'node_modules'],
alias: {
'@': path.resolve(import.meta.dirname, 'src/'),
'@components': path.resolve(import.meta.dirname, 'src/components'),
'@pages': path.resolve(import.meta.dirname, 'src/pages'),
'@assets': path.resolve(import.meta.dirname, 'src/assets'),
'@hooks': path.resolve(import.meta.dirname, 'src/hooks'),
'@utils': path.resolve(import.meta.dirname, 'src/utils'),
},
extensions: ['.tsx', '.ts', '.js', '.jsx'],
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
exclude: /node_modules/,
use: ['file-loader'],
},
],
},
devServer: {
static: './dist',
hot: true,
historyApiFallback: true,
port: 3000,
open: true,
},
};
};
export default createWebpackConfig;