-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (92 loc) · 2.64 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 path = require("path");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackInjector = require("html-webpack-injector");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
module.exports = {
entry: {
main: "./src/index.ts"
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "build"),
libraryTarget: "umd",
globalObject: "this"
},
module: {
rules: [
{
test: /\.(ttf|otf|woff2?)$/,
type: "asset/resource",
dependency: { not: ["url"] },
generator: {
filename: "assets/[name].[hash].[ext]"
}
},
{
test: /\.(js|mjs|ts)$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: "ts-loader"
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"]
},
{
test: /\.(png|jpe?g|gif)$/,
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath: "assets"
}
}
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, "./public/index.html"),
filename: path.join(__dirname, "./build/index.html"),
minify: false
}),
new HtmlWebpackInjector(),
new MiniCssExtractPlugin({
filename: "[name].bundle.css"
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserWebpackPlugin({
extractComments: false
}),
new CssMinimizerPlugin()
],
splitChunks: {
chunks: "all",
}
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"],
alias: {
"@": path.resolve(__dirname, "./src"),
"react/jsx-runtime": "jsx-dom/jsx-runtime.js"
}
},
devtool: "source-map",
devServer: {
static: {
directory: path.join(__dirname, "./build"),
},
open: true,
hot: true,
port: 5000,
}
};