-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
80 lines (75 loc) · 1.74 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
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const { resolveTsAliases } = require("resolve-ts-aliases");
const isProd = process.env.NODE_ENV === "production";
console.log({ e: process.env.NODE_ENV, __dirname });
const config = {
mode: isProd ? "production" : "development",
entry: {
index: "./src/index.tsx",
},
output: {
path: `${__dirname}/dist`,
publicPath: "/",
filename: "[name].js",
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
alias: resolveTsAliases(__dirname + "/tsconfig.json"),
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.svg$/,
use: ["@svgr/webpack", "file-loader"],
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
use: ["file-loader"],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "src/index.html",
favicon: "src/assets/favicon.ico",
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
],
};
if (isProd) {
config.optimization = {
minimizer: [new TerserWebpackPlugin()],
};
} else {
config.devServer = {
publicPath: "/",
port: 8080,
open: true,
hot: true,
compress: true,
stats: "errors-only",
overlay: true,
historyApiFallback: {
disableDotRule: true,
},
watchOptions: {
aggregateTimeout: 300,
poll: 1500,
ignored: 'node_modules/**'
}
};
}
module.exports = config;