This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (77 loc) · 2.04 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
const path = require('path')
const dotenv = require('dotenv')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { DefinePlugin } = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = (vars) => {
const env = {
...dotenv.config({ path: path.join(__dirname, '.env') }).parsed,
...vars,
}
return {
entry: './src/index.js',
output: {
path: path.join(__dirname, '/build'),
filename: 'bundle.[contenthash].js',
clean: true,
},
devServer: {
historyApiFallback: true,
port: 3000,
historyApiFallback: {
rewrites: [{ from: /./, to: '/index.html' }],
index: 'index.html',
},
},
optimization: {
nodeEnv: 'production',
minimize: true,
concatenateModules: true,
},
devtool: 'cheap-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
type: 'javascript/auto',
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp|avif|svg|woff|woff2)$/i,
type: 'asset',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new DefinePlugin({
'process.env': Object.keys(env).reduce((out, next) => {
out[next] = JSON.stringify(env[next])
return out
}, {}),
}),
new DefinePlugin({
VERSION: JSON.stringify(require('./package.json').version),
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new CopyPlugin({
patterns: [
{ from: path.resolve(__dirname, 'public', '*'), to: '[name][ext]' },
],
}),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled', // disable analyser. Replace with "server" or "static" to render analyser
}),
],
externals: {},
}
}