From 10ffdb489d270b7f72355c456669af6636228c3a Mon Sep 17 00:00:00 2001 From: Walter van der Giessen Date: Sun, 17 Dec 2023 19:30:11 +0100 Subject: [PATCH] Esm & commonjs support --- package.json | 8 ++++---- rollup.config.js | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e3c860d..60fb09f 100755 --- a/package.json +++ b/package.json @@ -13,11 +13,11 @@ "parallel" ], "types": "./dist/esm/index.d.ts", - "main": "./dist/cjs/index.js", - "module": "./dist/esm/index.js", + "main": "./dist/cjs/index.cjs", + "module": "./dist/esm/index.mjs", "exports": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" + "require": "./dist/cjs/index.cjs", + "import": "./dist/esm/index.mjs" }, "files": [ "./dist" diff --git a/rollup.config.js b/rollup.config.js index bed3753..991c9df 100755 --- a/rollup.config.js +++ b/rollup.config.js @@ -7,8 +7,9 @@ import inject from "@rollup/plugin-inject"; import fs from "node:fs"; import path from "node:path"; -export default ["esm", "cjs"].flatMap((type) => - ["", ".min"].map( +export default ["esm", "cjs"].flatMap((type) => { + const ext = type === "esm" ? "mjs" : "cjs"; + return ["", ".min"].map( (version) => /** @type {import('rollup').RollupOptions} */ ({ input: `src/index.ts`, @@ -24,17 +25,17 @@ export default ["esm", "cjs"].flatMap((type) => typescript(), replace({ __INLINE_WORKER__: fs - .readFileSync(`.temp/worker.${type}${version}.js`, "utf8") - .replaceAll("`", "\\`") - .replaceAll("$", "\\$"), + .readFileSync(`.temp/worker.${type}${version}.js`, "utf8") + .replaceAll("`", "\\`") + .replaceAll("$", "\\$"), }), inject({ - Worker: path.resolve(`src/lib/polyfills/Worker.${type}.ts`) + Worker: path.resolve(`src/lib/polyfills/Worker.${type}.ts`), }), ], output: [ { - file: `dist/${type}/index${version}.js`, + file: `dist/${type}/index${version}.${ext}`, format: type, sourcemap: false, name: "multithreading", @@ -57,5 +58,5 @@ export default ["esm", "cjs"].flatMap((type) => ], external: ["web-worker"], }) - ) -); + ); +});