-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
129 lines (117 loc) · 3.24 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
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
const path = require("path");
const webpack = require("webpack");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const Dotenv = require("dotenv-webpack");
let isDevelopment = process.env.NODE_ENV !== "production";
let isProduction = process.env.NODE_ENV === "production";
let isESLINT = process.env.ESLINT === "true";
let entry = { main: "./src/index.tsx" };
const plugins = [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.ProvidePlugin({
process: "process/browser.js",
}),
new Dotenv(),
isESLINT && new ESLintPlugin(),
].filter(Boolean);
if (isDevelopment) {
plugins.push(new ReactRefreshWebpackPlugin());
}
module.exports = {
mode: isDevelopment ? "development" : "production",
entry,
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
assetModuleFilename: "images/[hash][ext][query]",
publicPath: "/",
},
module: {
rules: [
{
test: /\.css$/i,
use: [
isDevelopment && require.resolve("style-loader"),
isProduction && {
loader: MiniCssExtractPlugin.loader,
options: { publicPath: "" },
},
{
loader: require.resolve("css-loader"),
options: {
importLoaders: 1,
sourceMap: isDevelopment,
},
},
].filter(Boolean),
sideEffects: true,
},
{
test: /\.(png|jpe?g|gif|svg|webp|ttf)$/i,
type: "asset",
},
// {
// test: /\.(ttf)$/,
// use: [
// {
// loader: "file-loader",
// options: {
// name: "[name].[ext]",
// outputPath: "fonts/",
// },
// },
// ],
// },
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
plugins: [
isDevelopment && require.resolve("react-refresh/babel"),
].filter(Boolean),
},
},
},
],
},
plugins,
resolve: {
fallback: {
http: require.resolve("stream-http"),
crypto: require.resolve("crypto-browserify"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify"),
buffer: require.resolve("buffer"),
stream: require.resolve("stream-browserify"),
},
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
// devtool: isDevelopment ? "source-map" : false,
devtool: false,
devServer: {
historyApiFallback: true,
client: {
logging: "error",
overlay: { errors: true, warnings: false },
progress: true,
reconnect: 0,
},
open: true,
port: 3001,
hot: true, // not necessary in the latest version of webpack by default true
},
};