-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathwebpack.config.js
101 lines (93 loc) · 2.63 KB
/
webpack.config.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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: 'development',
experiments: {
asyncWebAssembly: true,
syncWebAssembly: true
},
// Defines the entry point of the application
entry: './src/index.js',
// Controls how source maps are generated, if at all.
devtool: 'inline-source-map',
// Defines the output directory and filenames of bundled resources
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: './',
},
// Configuration for the development server
devServer: {
static: './dist',
open: true, // Open the browser after server had been started
historyApiFallback: true, // For Single Page Applications
hot: true, // Enable Hot Module Replacement
},
// Defines how different types of modules are treated
module: {
rules: [
// Adds support for JavaScript files
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
// Adds support for CSS files
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
// Adds support for image files
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
// Adds support for fonts and SVGs in CSS
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
type: 'asset/resource',
},
],
},
// Enables the use of additional plugins
plugins: [
// Generates an HTML file for your bundle
new HtmlWebpackPlugin({
title: 'Webpack App',
template: './src/index.html', // Load a custom template
inject: true, // Inject all files that are generated by webpack
}),
],
// Configure how modules are resolved
resolve: {
extensions: ['.js', '.jsx'], // Automatically resolve certain extensions
alias: {
// Create aliases
Components: path.resolve(__dirname, 'src/components/'),
// ... more aliases
},
},
// Optimization configuration
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// Get the name of the npm package
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return `npm.${packageName.replace('@', '')}`;
},
},
},
},
},
};