generated from ahuglajbclajep/my-react-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
53 lines (52 loc) · 1.55 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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin"); // from webpack
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const package = require("./package.json");
/** @type {(env: typeof process.env, argv: { mode?: string }) => import("webpack").Configuration} */
module.exports = (env, { mode }) => {
const dev = mode !== "production";
return {
// see https://github.com/webpack/webpack-dev-server/issues/1327
mode: "development",
entry: "./src/index",
module: {
rules: [
{
test: /\.[tj]sx?$/,
loader: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { esModule: true },
},
"css-loader",
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: package.name,
desc: package.description,
scriptLoading: "defer",
}),
new MiniCssExtractPlugin(),
],
resolve: { extensions: [".ts", ".tsx", ".js", ".jsx"] },
optimization: {
minimizer: [new TerserPlugin(), new OptimizeCssAssetsPlugin()],
},
devtool: dev ? "inline-source-map" : false,
devServer: {
contentBase: "./dist",
// host: "0.0.0.0", // for debugging on mobile devices
overlay: true,
watchContentBase: true,
},
};
};