-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (100 loc) · 2.86 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
102
103
104
const path = require('path');
const dotenv = require('dotenv');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const env = dotenv.config().parsed;
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
module.exports = (_env, argv) => {
const isDevelopment = argv.mode === 'development';
return {
entry: path.resolve(__dirname, './src/index.tsx'),
output: {
path: path.resolve(__dirname, 'build'),
filename: isDevelopment
? '[name].[fullhash].bundle.js'
: '[name].[contenthash].bundle.js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
plugins: [
isDevelopment && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
],
},
// {
// test: /\.s[ac]ss$/i,
// exclude: /node_modules/,
// use: [
// "style-loader",
// "css-loader",
// "sass-loader",
// "postcss-loader"
// ],
// },
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.(jpe?g|png|gif|eot|ttf|woff|woff2)$/i,
loader: 'file-loader',
exclude: /node_modules/,
options: {
name: '[path][name].[ext]',
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({ configFile: 'tsconfig.json' })],
},
devtool: 'source-map',
devServer: {
hot: true,
contentBase: path.resolve(__dirname, 'build'),
port: env.DEV_SERVER_PORT,
historyApiFallback: true,
host: 'localhost',
},
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
plugins: [
new webpack.DefinePlugin(envKeys),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new ErrorOverlayPlugin(),
isDevelopment && new ReactRefreshWebpackPlugin({ overlay: false }),
].filter(Boolean),
};
};