Skip to content

Commit 8b6b100

Browse files
committedOct 13, 2020
feat: add ES6 module export
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
1 parent 83a2356 commit 8b6b100

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎package.json

+5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
"files": [
1515
"dist/"
1616
],
17+
"type": "commonjs",
1718
"main": "./dist/index.js",
19+
"exports": {
20+
"import": "./wrapper.mjs",
21+
"require": "./dist/index.js"
22+
},
1823
"types": "./dist/index.d.ts",
1924
"license": "MIT",
2025
"repository": {

‎wrapper.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import io from "./dist/index.js";
2+
3+
export const Server = io.Server;

0 commit comments

Comments
 (0)
Please sign in to comment.