Skip to content

Commit

Permalink
improve bundler integration
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Sep 2, 2024
1 parent 737b230 commit 3197852
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
21 changes: 12 additions & 9 deletions packages/jimp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@
"exclude": [
"**/*.test.ts"
],
"esmDialects": [
"browser"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./fonts": "./src/fonts.ts",
"./browser": {
"types": "./dist/esm/index.d.ts",
"import": "./browser.js"
}
"./fonts": "./src/fonts.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
Expand All @@ -118,6 +121,10 @@
}
},
"./fonts": {
"browser": {
"types": "./dist/browser/fonts.d.ts",
"default": "./dist/browser/fonts.js"
},
"import": {
"types": "./dist/esm/fonts.d.ts",
"default": "./dist/esm/fonts.js"
Expand All @@ -126,10 +133,6 @@
"types": "./dist/commonjs/fonts.d.ts",
"default": "./dist/commonjs/fonts.js"
}
},
"./browser": {
"types": "./dist/esm/index.d.ts",
"import": "./browser.js"
}
},
"main": "./dist/commonjs/index.js",
Expand Down
26 changes: 25 additions & 1 deletion packages/jimp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ import alias from "@rollup/plugin-alias";
import nodePolyfills from "rollup-plugin-polyfill-node";
import inject from "@rollup/plugin-inject";
import terser from "@rollup/plugin-terser";
import { dts } from "rollup-plugin-dts";

import { promises as fs } from "fs";

async function maybeUnlink(path) {
try {
await fs.unlink(path);
} catch (error) {
if (error.code !== "ENOENT") {
throw error;
}
}
}

// Remove tshy's output
await maybeUnlink("dist/browser/index-browser.d.mts.map");
await maybeUnlink("dist/browser/index-browser.mjs.map");
await maybeUnlink("dist/browser/index.d.ts");
await maybeUnlink("dist/browser/index.js");

function injectCodePlugin(code) {
return {
Expand Down Expand Up @@ -62,11 +81,16 @@ export default [
],
output: [
{
file: `browser.js`,
file: "dist/browser/index.js",
format: "es",
sourcemap: true,
inlineDynamicImports: true,
},
],
},
{
input: `src/index.ts`,
output: [{ file: "dist/browser/index.d.ts", format: "es" }],
plugins: [dts()],
},
];
1 change: 1 addition & 0 deletions packages/jimp/src/index-browser.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// A stub. The real build is done by rollup.

0 comments on commit 3197852

Please sign in to comment.