-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.dev.js
134 lines (133 loc) · 3.85 KB
/
webpack.config.dev.js
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
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import path from 'path';
export default {
mode: 'development',
resolve: {
extensions: ['.js', '.jsx', '.json'], // Automatically resolve these extensions
},
devtool: 'cheap-module-source-map', // Fastest option for dev while still providing good debugging
entry: [
'./src/webpack-public-path',
'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'src/index.js'), // Defining path seems necessary for this to work consistently on Windows machines.
],
target: 'web',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js',
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__DEV__: true,
}),
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(), // React Fast Refresh plugin
new HtmlWebpackPlugin({
template: 'src/index.ejs',
favicon: 'src/Images/favicon.png',
minify: {
removeComments: true,
collapseWhitespace: true,
},
inject: true,
}),
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env', // Transpile modern JavaScript to ES5
'@babel/preset-react', // Transpile JSX and other React features
],
plugins: [
'react-refresh/babel', // For React Fast Refresh
'@babel/plugin-transform-react-constant-elements', // Optimization plugin for React
'babel-plugin-transform-react-remove-prop-types', // Removes propTypes in production builds
'@babel/plugin-transform-class-properties', // Enable class properties syntax
'@babel/plugin-transform-object-rest-spread', // Enable object rest/spread syntax
],
},
},
],
},
{
test: /\.eot(\?v=\d+.\d+.\d+)?$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name].[contenthash][ext]',
},
},
{
test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name].[contenthash][ext]',
},
},
{
test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name].[contenthash][ext]',
},
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
generator: {
filename: 'images/[name].[contenthash][ext]',
},
},
{
test: /\.(jpe?g|png|gif|ico)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name].[contenthash][ext]',
},
},
{
test: /(\.css|\.scss|\.sass)$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer'),
],
},
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
implementation: require('sass'), // Use Dart Sass instead of node-sass
sassOptions: {
includePaths: [path.resolve(__dirname, 'src', 'scss')],
},
sourceMap: true,
},
},
],
},
],
},
};