-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.ts
57 lines (55 loc) · 1.48 KB
/
webpack.config.ts
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
import path from "path";
import webpack from "webpack";
import HtmlPlugin from "html-webpack-plugin";
const config: webpack.Configuration = {
mode: process.env.NODE_ENV !== "production" ? "development" : "production",
entry: path.resolve(__dirname, "src/bundle.js"),
output: {
path: path.resolve(__dirname, "public/js"),
filename: "bundle.[contenthash].min.js",
},
module: {
rules: [
{
exclude: /(node_modules)/,
loader: "babel-loader",
test: /\.[tj]sx?$/,
},
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
fallback: {
http: false,
https: false,
path: false,
fs: false,
zlib: false,
os: false,
util: require.resolve("util"),
url: require.resolve("url"),
buffer: require.resolve("buffer"),
},
},
// devtool: "inline-source-map",
plugins: [
new HtmlPlugin({
filename: path.resolve(__dirname, "public/index.html"),
template: path.resolve(__dirname, "public/index.html"),
}),
// fix "process is not defined" error:
// (do "npm install process" before running the build)
new webpack.ProvidePlugin({
process: "process/browser",
}),
// fix "Buffer is undefined" error:
// https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.DefinePlugin({
setImmediate: (cb: () => void) => cb(),
}),
],
};
export default config;