-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (79 loc) · 2.16 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
require("dotenv").config();
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const isProduction = process.env.NODE_ENV === "production";
const SRC_DIR = path.resolve(__dirname, "src");
const OUT_DIR = path.resolve(__dirname, "build");
module.exports = {
entry: path.resolve(SRC_DIR, "index.tsx"),
output: {
path: OUT_DIR,
filename: "static/js/[name].[contenthash:8].js",
chunkFilename: "static/js/[name].[contenthash:8].chunk.js",
publicPath: "/",
},
devServer: {
open: true,
host: process.env.HOST || "localhost",
port: parseInt(process.env.PORT || "8000", 10),
historyApiFallback: true,
},
module: {
rules: [
{
use: [
isProduction ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
],
test: /\.css/i,
include: /src/,
},
{
loader: "babel-loader",
test: /\.(js|jsx|ts|tsx)$/i,
exclude: /node_modules/,
},
{
loader: "file-loader",
test: /\.(jpe?g|png|svg)$/i,
options: {
name: "static/media/[name][hash:8].[ext]",
},
},
{
loader: "file-loader",
test: /\.(woff|woff2|eot|ttf|otf)$/i,
options: {
name: "static/fonts/[name][hash:8].[ext]",
},
},
],
},
resolve: {
extensions: ["*", "...", ".jsx", ".tsx", ".ts"],
},
plugins: [
new HtmlWebpackPlugin({
title: process.env.APP_TITLE || "Untitled",
inject: true,
template: path.resolve(SRC_DIR, "index.html"),
favicon: path.resolve(SRC_DIR, "assets", "icons", "react.png"),
...(isProduction && {
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeEmptyAttributes: true,
useShortDoctype: true,
minifyCSS: true,
minifyJS: true,
minifyURSLs: true,
},
}),
}),
],
};