Skip to content

Commit

Permalink
Esm & commonjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
W4G1 committed Dec 17, 2023
1 parent c263c74 commit 10ffdb4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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",
Expand All @@ -57,5 +58,5 @@ export default ["esm", "cjs"].flatMap((type) =>
],
external: ["web-worker"],
})
)
);
);
});

0 comments on commit 10ffdb4

Please sign in to comment.