-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.ts
111 lines (106 loc) · 3.14 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
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
import * as path from "path";
import * as webpack from "webpack";
import * as server from "webpack-dev-server";
import * as html from "html-webpack-plugin";
import * as vanilla from "@vanilla-extract/webpack-plugin";
import * as terser from "terser-webpack-plugin";
import * as copy from "copy-webpack-plugin";
import * as MiniCssExtractPlugin from "mini-css-extract-plugin";
import ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
type ExtendedConfig = webpack.Configuration & { devServer: server.Configuration };
type ConfigSelector = (env: any, argv: any) => ExtendedConfig;
const config: ConfigSelector = (env, argv) => {
console.log("Passed env:", env);
console.log("Passed argv:", argv);
const mode = argv.mode ?? "production";
console.log("Current mode:", mode);
return {
mode,
entry: {
"klend": "./src/index.tsx"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "scripts/[name].bundle.js",
publicPath: "/"
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
fallback: {
"buffer": require.resolve("buffer/"),
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"assert": false,
"path": false,
"util": false,
"os": false,
"fs": false,
"vm": false,
"http": false, // for wallet provider
"https": false, // for wallet provider
"url": false, // for wallet provider
"zlib": false, // for wallet provider
},
alias: {
process: "process/browser",
"@components": path.resolve(__dirname, "src/components"),
"@queries": path.resolve(__dirname, "src/queries"),
"@misc": path.resolve(__dirname, "src/misc"),
"@theme": path.resolve(__dirname, "src/theme"),
}
},
module: {
rules: [{
test: /\.tsx?$/,
use: {
loader: "ts-loader"
},
exclude: /node_modules/
}, {
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
}]
},
plugins: [
new html({ template: "public/index.html", inject: "head" }),
new copy({ patterns: [{ from: "public/icon_32.png" }] }),
new copy({ patterns: [{ from: "public/icon_128.png" }] }),
new vanilla.VanillaExtractPlugin(),
new MiniCssExtractPlugin({ filename: "theme.css" }),
new ForkTsCheckerWebpackPlugin(),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: 'process/browser',
})
],
optimization: {
minimize: mode === "production" ? true : false,
minimizer: [new terser()],
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
name: "vendors",
chunks: "all"
}
}
}
},
devServer: {
compress: false,
historyApiFallback: true,
static: {
directory: path.resolve(__dirname, "dist"),
},
client: {
overlay: false
}
},
stats: {
warnings: false,
errors: true,
timings: true
},
};
};
export default config;