Skip to content

Commit

Permalink
feat: add ES6 module export
Browse files Browse the repository at this point in the history
- with `{ "type": "commonjs" }` in the package.json file

```js
const io = require("socket.io-client");

const socket = io("/");
```

- with `{ "type": "module" }`

```js
import io from "socket.io-client";

const socket = io("/");

// or
import { Manager } from "socket.io-client";

const manager = new Manager();
const socket = manager.socket("/");
```

Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
  • Loading branch information
darrachequesne committed Oct 13, 2020
1 parent e826992 commit cbabb03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
"dist/",
"build/"
],
"type": "commonjs",
"main": "./build/index.js",
"exports": {
"./package.json": "./package.json",
"./dist/socket.io.js": "./dist/socket.io.js",
"./dist/socket.io.js.map": "./dist/socket.io.js.map",
".": {
"import": "./wrapper.mjs",
"require": "./build/index.js"
}
},
"types": "./build/index.d.ts",
"dependencies": {
"backo2": "1.0.2",
Expand Down
4 changes: 4 additions & 0 deletions wrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import io from "./build/index.js";

export const Manager = io.Manager;
export default io;

0 comments on commit cbabb03

Please sign in to comment.