From d4baf0ce3a626b95f505048d1112d84d7f319193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= <188768+fb55@users.noreply.github.com> Date: Fri, 8 Apr 2022 17:18:29 +0100 Subject: [PATCH] feat: Add ESM build --- package.json | 14 ++++++++++++-- src/index.ts | 4 ++-- tsconfig.json | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6265ea1c..f400721e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,11 @@ "license": "BSD-2-Clause", "main": "lib/index.js", "types": "lib/index.d.ts", + "module": "lib/esm/index.js", + "exports": { + "require": "./lib/index.js", + "import": "./lib/esm/index.js" + }, "sideEffects": false, "files": [ "lib" @@ -18,7 +23,9 @@ "test:jest": "jest", "lint": "eslint src", "format": "prettier --write '**/*.{ts,md,json}'", - "build": "tsc", + "build": "npm run build:cjs && npm run build:esm", + "build:cjs": "tsc", + "build:esm": "tsc --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json", "prepare": "npm run build" }, "repository": { @@ -50,7 +57,10 @@ }, "jest": { "preset": "ts-jest", - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^(.*)\\.js$": "$1" + } }, "prettier": { "tabWidth": 4 diff --git a/src/index.ts b/src/index.ts index a6e5c781..49f389cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,9 +9,9 @@ import { Document, ProcessingInstruction, ParentNode, -} from "./node"; +} from "./node.js"; -export * from "./node"; +export * from "./node.js"; export interface DomHandlerOptions { /** diff --git a/tsconfig.json b/tsconfig.json index 5d16dc75..7287cc50 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,7 @@ /* Module Resolution Options */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "moduleResolution": "node", "resolveJsonModule": true }, "include": ["src"],