Skip to content

Commit

Permalink
feat: add ES6 module export
Browse files Browse the repository at this point in the history
Both CommonJS and ES6 import are now supported:

- with `{ "type": "commonjs" }` in the package.json file

```js
const io = require("socket.io")(8080);
// or
const { Server } = require("socket.io");
const io = new Server(8080);
```

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

```js
import { Server } from "socket.io";

const io = new Server(8080);
```

Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
  • Loading branch information
darrachequesne committed Oct 13, 2020
1 parent 83a2356 commit 8b6b100
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"files": [
"dist/"
],
"type": "commonjs",
"main": "./dist/index.js",
"exports": {
"import": "./wrapper.mjs",
"require": "./dist/index.js"
},
"types": "./dist/index.d.ts",
"license": "MIT",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions wrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import io from "./dist/index.js";

export const Server = io.Server;

0 comments on commit 8b6b100

Please sign in to comment.