-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
146 lines (132 loc) · 3.62 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const distPath = path.resolve(__dirname, "dist");
const srcPath = path.resolve(__dirname, "src");
const templatePath = path.resolve(__dirname, "src/index.html");
const entryFile = srcPath + "/index.tsx";
module.exports = (env) => {
env = env || {};
const ghPagesMode = env.ghpages !== undefined;
return {
mode: env.development ? "development" : "production",
devtool: env.development ? "eval-cheap-module-source-map" : undefined,
optimization: {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 0,
maxSize: 240000,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
},
},
},
},
entry: entryFile,
output: {
filename: env.development ? "[name].js" : "[name].[contenthash].js",
path: distPath,
publicPath: ghPagesMode ? "/image-color-picker/" : "",
clean: env.clean === "true",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: true,
babelrc: false,
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
plugins: [...(env.development ? ["react-refresh/babel"] : [])],
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
MiniCSSExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: {
localIdentName: "[name]__[local]__[contenthash:base64:5]",
},
},
},
"postcss-loader",
],
exclude: /node_modules/,
},
{
test: /\.(jpg|png)$/,
type: "asset/resource",
generator: {
filename: "assets/img/[name].[ext]",
},
},
{
test: /\.(ttf|otf)$/,
type: "asset/resource",
generator: {
filename: "assets/fonts/[name].[ext]",
},
},
],
},
devServer: {
hot: true,
port: process.env.PORT || 3000,
static: "dist/",
historyApiFallback: true,
client: {
overlay: {
warnings: false,
},
},
},
plugins: [
new HtmlWebpackPlugin({ template: templatePath }),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: "write-references",
},
}),
env.development && new ReactRefreshWebpackPlugin(),
new MiniCSSExtractPlugin({
ignoreOrder: true,
}),
new webpack.DefinePlugin({
__CONFIG: JSON.stringify(env.config),
__DEV: !!env.development,
}),
].filter(Boolean),
stats: {
hash: false,
version: false,
chunks: false,
modules: false,
children: false,
colors: true,
},
};
};