Skip to content

Commit 8be8c5b

Browse files
committed
do not include wasm in the default bundle js
because it increses the size of bundle +5KiB (+base64-js dep)
1 parent aaf70e2 commit 8be8c5b

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

karma.conf.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { sauceLabs, sauceLaunchers } from "./sauceLabs";
22

33
const webpackConfig = require("./webpack.config.js");
4+
const webpack = require("webpack");
45

56
export default function configure(config: any) {
67
config.set({
@@ -61,12 +62,16 @@ export default function configure(config: any) {
6162
},
6263
],
6364
},
65+
plugins: [
66+
new webpack.DefinePlugin({
67+
"process.env.MSGPACK_WASM": JSON.stringify(process.env.MSGPACK_WASM),
68+
}),
69+
],
6470
optimization: {
6571
minimize: false,
6672
},
6773
performance: {
68-
maxEntrypointSize: 50 * 1024 ** 2,
69-
maxAssetSize: 50 * 1024 ** 2,
74+
hints: false,
7075
},
7176
devtool: "inline-source-map",
7277
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"karma-sauce-launcher": "^2.0.2",
6868
"karma-sourcemap-loader": "^0.3.7",
6969
"karma-webpack": "^3.0.5",
70+
"lodash": "^4.17.11",
7071
"mocha": "^6.1.4",
7172
"msgpack-lite": "^0.1.26",
7273
"msgpack-test-js": "^1.0.0",

tools/pack-wasm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var wasmInstance = new WebAssembly.Instance(wasmModule, {
2727
env: {
2828
abort: function (filename, line, column) {
2929
// FIXME: filename is just a number (pointer?)
30-
throw new Error(\`abort called at \${filename}:\${line}:\${column}\`);
30+
throw new Error("abort called at " + filename + ":" + line + ":" + column);
3131
},
3232
},
3333
});

tsconfig.dist.webpack.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"outDir": "./build/es5",
77
"declaration": false,
88
"downlevelIteration": true,
9-
"noEmitOnError": true,
10-
"incremental": false,
9+
"noEmitOnError": true
1110
},
1211
"include": ["src/**/*.ts"]
1312
}

webpack.config.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"use strict";
22

33
const path = require("path");
4+
const webpack = require("webpack");
45
const { CheckEsVersionPlugin } = require("@bitjourney/check-es-version-webpack-plugin");
5-
module.exports = {
6+
const _ = require("lodash");
7+
8+
const config = {
69
mode: "production",
710

811
entry: "./src/index.ts",
912
output: {
1013
path: path.resolve(__dirname, "dist.es5"),
11-
filename: "msgpack.js",
1214
libraryTarget: "commonjs",
1315
},
1416
resolve: {
@@ -26,7 +28,17 @@ module.exports = {
2628
],
2729
},
2830

29-
// We use webpack just to reduce filesystem accesses
31+
plugins: [
32+
new CheckEsVersionPlugin({
33+
esVersion: 5, // for IE11 support
34+
}),
35+
],
36+
externals: {
37+
"base64-js": {
38+
commonjs: "base64-js",
39+
},
40+
},
41+
3042
optimization: {
3143
noEmitOnErrors: true,
3244
minimize: false,
@@ -36,11 +48,34 @@ module.exports = {
3648
// https://webpack.js.org/configuration/node/
3749
node: false,
3850

39-
plugins: [
40-
new CheckEsVersionPlugin({
41-
esVersion: 5, // for IE11 support
42-
}),
43-
],
44-
4551
devtool: "source-map",
4652
};
53+
54+
module.exports = [
55+
// default bundle does not includes wasm
56+
((config) => {
57+
config.output.filename = "msgpack.js";
58+
config.plugins.push(
59+
new webpack.DefinePlugin({
60+
// The default bundle does not includes WASM
61+
"process.env.MSGPACK_WASM": JSON.stringify("never"),
62+
"process.env.WASM": JSON.stringify(null),
63+
}),
64+
new webpack.IgnorePlugin(/\.\/dist\/wasm\/msgpack\.wasm\.js$/),
65+
);
66+
return config;
67+
})(_.cloneDeep(config)),
68+
69+
// +wsm
70+
((config) => {
71+
config.output.filename = "msgpack+wasm.js";
72+
config.plugins.push(
73+
new webpack.DefinePlugin({
74+
// The default bundle does not includes WASM
75+
"process.env.MSGPACK_WASM": JSON.stringify(null),
76+
"process.env.WASM": JSON.stringify(null),
77+
}),
78+
);
79+
return config;
80+
})(_.cloneDeep(config)),
81+
];

0 commit comments

Comments
 (0)