From 71d60480af9ea06d22792540dafb18a76e9362e7 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sat, 24 Oct 2020 00:10:10 +0200 Subject: [PATCH] feat: add bundle with msgpack parser Pros: - events with binary content are sent as 1 WebSocket frame (instead of 2 with the default parser) - payloads with lots of numbers should be smaller Cons: - no IE9 support (https://caniuse.com/mdn-javascript_builtins_arraybuffer) - a slightly bigger bundle size (61.1 vs 59.9 KB) Source: https://github.com/darrachequesne/socket.io-msgpack-parser --- package.json | 3 ++- support/msgpack-parser.config.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 support/msgpack-parser.config.js diff --git a/package.json b/package.json index 1692e4a67..f0337b607 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "prettier": "^2.1.2", "socket.io": "3.0.0-rc2", "socket.io-browsers": "^1.0.0", + "socket.io-msgpack-parser": "^3.0.0", "text-blob-builder": "0.0.1", "ts-loader": "^8.0.5", "ts-node": "^9.0.0", @@ -72,7 +73,7 @@ "test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi", "test:node": "mocha --require ts-node/register --reporter dot --require test/support/server.js test/index.js", "test:browser": "zuul test/index.js", - "build": "npm run compile && webpack --config ./support/webpack.config.js --config ./support/prod.config.js", + "build": "npm run compile && webpack --config ./support/webpack.config.js --config ./support/prod.config.js --config ./support/msgpack-parser.config.js", "format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.js' 'test/**/*.ts' 'support/**/*.js'", "format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.js' 'test/**/*.ts' 'support/**/*.js'", "prepack": "npm run compile" diff --git a/support/msgpack-parser.config.js b/support/msgpack-parser.config.js new file mode 100644 index 000000000..44318e043 --- /dev/null +++ b/support/msgpack-parser.config.js @@ -0,0 +1,17 @@ +const { NormalModuleReplacementPlugin } = require("webpack"); +const config = require("./prod.config"); + +module.exports = { + ...config, + output: { + ...config.output, + filename: "socket.io.msgpack.min.js", + }, + plugins: [ + ...config.plugins, + new NormalModuleReplacementPlugin( + /^socket.io-parser$/, + "socket.io-msgpack-parser" + ), + ], +};