-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
112 lines (104 loc) · 2.74 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
112
import path from "path";
import webpack from "webpack";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
import WasmPackPlugin from "@wasm-tool/wasm-pack-plugin";
import TerserPlugin from "terser-webpack-plugin";
const nodeEnv = process.env.NODE_ENV;
console.log("NODE_ENV:", nodeEnv);
type ConfMode = "development" | "production" | "none";
let nodeMode: ConfMode;
if (nodeEnv === undefined) {
nodeMode = "development";
} else if (nodeEnv === "development" || nodeEnv === "production" || nodeEnv === "none") {
nodeMode = nodeEnv;
} else {
console.log("Invalid NODE_ENV:", nodeEnv);
console.log("NODE_ENV must be \"developemnt\", \"production\" or \"none\"");
throw 1;
}
const mode: ConfMode = nodeMode;
// @types/webpack doesn't include definition for optimization.mangleWasmImports.
// However, mangleWasmImports made the bundle slightly larger anyway.
const config: webpack.Configuration = {
optimization: {
// runtimeChunk: true,
// mangleWasmImports: true,
// minimize: false,
// usedExports: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({}),
],
},
mode: mode,
entry: {
index: "./src/index.ts",
style: "./src/style.styl",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle-[name].js",
library: "index",
libraryTarget: "window",
},
performance: {
hints: process.env.NODE_ENV === "production" ? "warning" : false,
},
resolve: {
extensions: [".ts", ".js", ".json"],
},
experiments: {
asyncWebAssembly: true,
},
plugins: [
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "./vita-wasm"),
}),
new CopyPlugin({
patterns: [
{ from: "src/index.html", to: "index.html" },
{ context: "src/icons", from: "*.ico" },
{ context: "src/icons", from: "*.png" },
{ context: "src/icons", from: "*.svg" },
{ context: "src/assets", from: "*.*" },
],
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// all options are optional
filename: "[name].css",
chunkFilename: "[id].css",
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
],
module: {
rules: [{
test: /\.ts$/,
use: [{
loader: "ts-loader",
options: {
// configFile: "tsconfig.json"
},
}],
exclude: /node_modules/,
}, {
test: /\.(css|styl)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// You can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: "../",
},
},
// "style-loader",
"css-loader",
"stylus-loader",
],
}],
},
};
export default config;