This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
76 lines (74 loc) · 2.03 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
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const InlineChunkHtmlPlugin = require("inline-chunk-html-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HTMLInlineCSSWebpackPlugin =
require("html-inline-css-webpack-plugin").default;
const HtmlInlineScriptPlugin = require("html-inline-script-webpack-plugin");
const isInline = process.env.INLINE;
module.exports = {
mode: process.env.NODE_ENV || "development",
devtool: process.env.NODE_ENV === "production" ? false : "inline-source-map",
entry: {
main: "./src/index.ts",
},
output: {
path: path.resolve(__dirname, "./build"),
publicPath: "",
filename: "bundle.js",
},
resolve: {
extensions: [".ts", ".js"],
fallback: {
buffer: require.resolve("buffer/"),
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new HtmlWebpackPlugin({
inject: "body",
template: "src/index.html",
}),
new webpack.DefinePlugin({
"process.env": "production",
"process.version": '"v12.20.1"',
}),
new MiniCssExtractPlugin(),
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime/]),
new HTMLInlineCSSWebpackPlugin(),
...(isInline ? [new HtmlInlineScriptPlugin()] : []),
],
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/i,
type: "asset/inline",
},
{
test: /\.ts$/,
loader: "ts-loader",
},
],
},
performance: { hints: false },
optimization: {
minimize: process.env.NODE_ENV === "production",
removeAvailableModules: true,
usedExports: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
terserOptions: {},
}),
],
},
};