generated from ahuglajbclajep/my-react-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
68 lines (67 loc) · 2.05 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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { GenerateSW } = require("workbox-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin"); // from webpack
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const package = require("./package.json");
/** @type {import("webpack").ConfigurationFactory} */
module.exports = (env, { mode }) => {
const dev = mode !== "production";
return {
// see https://github.com/webpack/webpack-dev-server/issues/1327
mode: "development",
entry: "./src/index",
// see https://github.com/webpack-contrib/worker-loader/issues/142
output: { globalObject: "self" },
module: {
rules: [
{
test: /\.?worker\.[tj]s$/,
// comlink-loader also receives worker-loader options
use: "comlink-loader?singleton&name=[name].js",
},
{
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(),
new GenerateSW({
clientsClaim: true,
skipWaiting: true,
inlineWorkboxRuntime: true,
sourcemap: dev,
}),
],
resolve: { extensions: [".ts", ".tsx", ".js", ".jsx"] },
optimization: {
minimizer: [new TerserPlugin(), new OptimizeCssAssetsPlugin()],
},
devtool: dev ? "inline-source-map" : false,
devServer: {
// host: "0.0.0.0", // for debugging on mobile devices
historyApiFallback: true,
contentBase: "./public", // for static file serving
// watchContentBase: true,
overlay: true,
},
};
};