forked from keybase/msgpack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
100 lines (91 loc) · 2.37 KB
/
webpack.config.ts
File metadata and controls
100 lines (91 loc) · 2.37 KB
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
import path from "path";
// @ts-ignore
import webpack from "webpack";
// @ts-ignore
import { CheckEsVersionPlugin } from "@bitjourney/check-es-version-webpack-plugin";
// @ts-ignore
import _ from "lodash";
const config = {
mode: "production",
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, "dist.es5"),
library: "MessagePack",
libraryTarget: "umd",
globalObject: "this",
},
resolve: {
extensions: [".ts", ".tsx", ".mjs", ".js", ".json", ".wasm"],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
configFile: "tsconfig.dist.webpack.json",
},
},
],
},
plugins: [
new CheckEsVersionPlugin({
esVersion: 5, // for IE11 support
}),
new webpack.DefinePlugin({
"process.env.WASM": JSON.stringify(null), // use only MSGPACK_WASM
"process.env.TEXT_ENCODING": JSON.stringify("null"),
"process.env.TEXT_DECODER": JSON.stringify(null),
}),
],
externals: {
"base64-js": {
commonjs: "base64-js",
commonjs2: "base64-js",
},
},
optimization: {
noEmitOnErrors: true,
minimize: false,
},
// We don't need NodeJS stuff on browsers!
// https://webpack.js.org/configuration/node/
node: false,
devtool: "source-map",
};
export default [
// default minified bundle does not includes wasm
((config) => {
config.output.filename = "msgpack.min.js";
config.plugins.push(
new webpack.DefinePlugin({
"process.env.MSGPACK_WASM": JSON.stringify("never"),
}),
new webpack.IgnorePlugin(/\.\/dist\/wasm\/msgpack\.wasm\.js$/),
);
config.optimization.minimize = true;
return config;
})(_.cloneDeep(config)),
// default bundle does not includes wasm
((config) => {
config.output.filename = "msgpack.js";
config.plugins.push(
new webpack.DefinePlugin({
// The default bundle does not includes WASM
"process.env.MSGPACK_WASM": JSON.stringify("never"),
}),
new webpack.IgnorePlugin(/\.\/dist\/wasm\/msgpack\.wasm\.js$/),
);
return config;
})(_.cloneDeep(config)),
// +wsm
((config) => {
config.output.filename = "msgpack+wasm.js";
config.plugins.push(
new webpack.DefinePlugin({
"process.env.MSGPACK_WASM": JSON.stringify(null),
}),
);
return config;
})(_.cloneDeep(config)),
];