-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (88 loc) · 2.23 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
const { resolve } = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const app = require("./src/config/app.json");
function modify(buffer) {
const manifest = JSON.parse(buffer.toString());
manifest.name = app.title;
manifest.description = app.description;
return JSON.stringify(manifest, null, 2);
}
module.exports = (env, options) => {
const isProd = options.mode === "production";
const config = {
mode: options.mode,
entry: {
index: "./src/index.tsx",
},
output: {
path: resolve(__dirname, "build"),
filename: "[name].[contenthash].js",
chunkFilename: "data/[name].[contenthash].chunk.js",
assetModuleFilename: "assets/fonts/[name].[ext]",
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.(woff|woff2)(\?.*)?$/,
type: "asset/resource",
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
...app,
template: "src/index.ejs",
}),
new CopyWebpackPlugin({
patterns: [
{ from: "./src/assets", to: "./assets" },
{
from: "./src/manifest.json",
to: "./manifest.json",
transform(content) {
return modify(content);
},
},
],
}),
],
};
if (isProd) {
config.devtool = "source-map";
config.optimization = {
usedExports: true,
minimizer: [new TerserWebpackPlugin({ extractComments: false })],
};
} else {
config.devtool = "eval-source-map";
config.devServer = {
port: 8080,
open: true,
hot: true,
static: {
directory: resolve(__dirname, "src/assets"),
publicPath: '/',
watch: true,
},
client: {
overlay: {
errors: true,
warnings: false,
},
},
};
}
return config;
};