diff --git a/package.json b/package.json index a623a40b7..1c53898e1 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "typescript": "^4.5.5" }, "scripts": { - "build": "tsc --build packages/* test", + "build": "npm run build:esm && npm run build:cjs", + "build:esm": "tsc --build packages/* test", + "build:cjs": "tsc -p packages/parse5/tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > packages/parse5/dist/cjs/package.json", "prettier": "prettier '**/*.{js,ts,md,json,yml}' --loglevel warn", "format": "npm run format:es && npm run format:prettier", "format:es": "npm run lint:es -- --fix", diff --git a/packages/parse5/package.json b/packages/parse5/package.json index 701c6a01b..f010d5c7d 100644 --- a/packages/parse5/package.json +++ b/packages/parse5/package.json @@ -27,7 +27,15 @@ "serialize" ], "license": "MIT", - "main": "dist/index.js", + "main": "dist/cjs/index.js", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "dist/index.js", + "require": "dist/cjs/index.js" + } + }, "repository": { "type": "git", "url": "git://github.com/inikulin/parse5.git" diff --git a/packages/parse5/tsconfig.cjs.json b/packages/parse5/tsconfig.cjs.json new file mode 100644 index 000000000..760382867 --- /dev/null +++ b/packages/parse5/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "target": "ES6", + "outDir": "dist/cjs" + } +}