Skip to content

Commit 5582477

Browse files
authored
feat: Add ESM build (#806)
1 parent acc934b commit 5582477

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"license": "BSD-2-Clause",
1010
"main": "lib/index.js",
1111
"types": "lib/index.d.ts",
12+
"module": "lib/esm/index.js",
13+
"exports": {
14+
"require": "./lib/index.js",
15+
"import": "./lib/esm/index.js"
16+
},
1217
"sideEffects": false,
1318
"files": [
1419
"lib"
@@ -18,7 +23,9 @@
1823
"test:jest": "jest",
1924
"lint": "eslint src",
2025
"format": "prettier --write '**/*.{ts,md,json}'",
21-
"build": "tsc",
26+
"build": "npm run build:cjs && npm run build:esm",
27+
"build:cjs": "tsc",
28+
"build:esm": "tsc --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json",
2229
"prepare": "npm run build"
2330
},
2431
"repository": {
@@ -50,7 +57,10 @@
5057
},
5158
"jest": {
5259
"preset": "ts-jest",
53-
"testEnvironment": "node"
60+
"testEnvironment": "node",
61+
"moduleNameMapper": {
62+
"^(.*)\\.js$": "$1"
63+
}
5464
},
5565
"prettier": {
5666
"tabWidth": 4

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
Document,
1010
ProcessingInstruction,
1111
ParentNode,
12-
} from "./node";
12+
} from "./node.js";
1313

14-
export * from "./node";
14+
export * from "./node.js";
1515

1616
export interface DomHandlerOptions {
1717
/**

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/* Module Resolution Options */
2323
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
2424
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
25+
"moduleResolution": "node",
2526
"resolveJsonModule": true
2627
},
2728
"include": ["src"],

0 commit comments

Comments
 (0)