Skip to content

Commit 27de300

Browse files
chore: migrate to rollup
This change allows us to: - reduce the size of the bundle - provide an ESM bundle (for usage in <script type="module">) BREAKING CHANGE: due to how default export works with ES modules, we have removed the default export of the library, which means the following code: ```js require("engine.io-client")(...); ``` will not work anymore. The named export must be used instead: ```js const { Socket } = require("engine.io-client); // or import { Socket } from "engine.io-client"; const socket = new Socket(...); ``` Note: the UMD build still exposes a function though: ```html <script src="/path/to/engine.io.js"></script> <script> const socket = eio(...); </script> ``` Note: webpack is still used with zuul because of the custom builder (zuul-builder-webpack)
1 parent 221433e commit 27de300

14 files changed

+391
-45
lines changed

README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Engine.IO is a commonjs module, which means you can include it by using
4141
1. write your app code
4242

4343
```js
44-
const socket = require('engine.io-client')('ws://localhost');
44+
const { Socket } = require('engine.io-client');
45+
const socket = new Socket('ws://localhost');
4546
socket.on('open', () => {
4647
socket.on('message', (data) => {});
4748
socket.on('close', () => {});
@@ -65,7 +66,7 @@ Engine.IO is a commonjs module, which means you can include it by using
6566
```html
6667
<script src="/path/to/engine.io.js"></script>
6768
<script>
68-
const socket = new eio.Socket('ws://localhost/');
69+
const socket = eio('ws://localhost/');
6970
socket.binaryType = 'blob';
7071
socket.on('open', () => {
7172
socket.send(new Int8Array(5));
@@ -80,7 +81,8 @@ Engine.IO is a commonjs module, which means you can include it by using
8081
Add `engine.io-client` to your `package.json` and then:
8182
8283
```js
83-
const socket = require('engine.io-client')('ws://localhost');
84+
const { Socket } = require('engine.io-client');
85+
const socket = new Socket('ws://localhost');
8486
socket.on('open', () => {
8587
socket.on('message', (data) => {});
8688
socket.on('close', () => {});
@@ -95,7 +97,8 @@ const opts = {
9597
ca: fs.readFileSync('test/fixtures/ca.crt')
9698
};
9799
98-
const socket = require('engine.io-client')('ws://localhost', opts);
100+
const { Socket } = require('engine.io-client');
101+
const socket = new Socket('ws://localhost', opts);
99102
socket.on('open', () => {
100103
socket.on('message', (data) => {});
101104
socket.on('close', () => {});
@@ -111,7 +114,8 @@ const opts = {
111114
}
112115
};
113116
114-
const socket = require('engine.io-client')('ws://localhost', opts);
117+
const { Socket } = require('engine.io-client');
118+
const socket = new Socket('ws://localhost', opts);
115119
socket.on('open', () => {
116120
socket.on('message', (data) => {});
117121
socket.on('close', () => {});
@@ -124,13 +128,13 @@ Please note that in this case the headers won't be sent in the WebSocket upgrade
124128
125129
```js
126130
// WILL NOT WORK in the browser
127-
require('engine.io-client')('http://localhost', {
131+
const socket = new Socket('http://localhost', {
128132
extraHeaders: {
129133
'X-Custom-Header-For-My-Project': 'will not be sent'
130134
}
131135
});
132136
// WILL NOT WORK
133-
require('engine.io-client')('http://localhost', {
137+
const socket = new Socket('http://localhost', {
134138
transports: ['websocket'], // polling is disabled
135139
transportOptions: {
136140
polling: {
@@ -141,7 +145,7 @@ require('engine.io-client')('http://localhost', {
141145
}
142146
});
143147
// WILL WORK
144-
require('engine.io-client')('http://localhost', {
148+
const socket = new Socket('http://localhost', {
145149
transports: ['polling', 'websocket'],
146150
transportOptions: {
147151
polling: {

lib/browser-entrypoint.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Socket } from "./socket.js";
2+
3+
export default (uri, opts) => new Socket(uri, opts);

lib/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Socket } from "./socket.js";
22

3-
export default (uri, opts) => new Socket(uri, opts);
4-
5-
/**
6-
* Expose deps for legacy compatibility
7-
* and standalone browser access.
8-
*/
93
export { Socket };
104
export { SocketOptions } from "./socket.js";
115
export const protocol = Socket.protocol;

0 commit comments

Comments
 (0)