Skip to content

Commit febc853

Browse files
improve bundler integration (#1321)
* improve bundler integration * update docs * fix docs startup
1 parent 737b230 commit febc853

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

packages/docs/astro.config.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ export default defineConfig({
3434
"../../packages/jimp/src/index.ts",
3535
"../../packages/jimp/src/fonts.ts",
3636
],
37-
tsconfig: "../../packages/jimp/tsconfig.json",
37+
tsconfig: "../../packages/jimp/tsconfig.docs.json",
3838
typeDoc: {
3939
groupOrder: ["Classes", "Functions", "Enumerations", "Variables"],
4040
sort: ["static-first", "alphabetical"],
4141
plugin: [
4242
path.join(
4343
path.dirname(import.meta.url).replace("file:", ""),
44-
"./src/typedoc-plugin.js",
44+
"./src/typedoc-plugin.js"
4545
),
4646
"typedoc-plugin-zod",
4747
path.join(
4848
path.dirname(import.meta.url).replace("file:", ""),
49-
"./src/typedoc-zod-extended.js",
49+
"./src/typedoc-zod-extended.js"
5050
),
5151
],
5252
},

packages/docs/src/components/grayscale-example.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useEffect, useState } from "react";
22

3-
// This version is bundled into a single file that can be used in the browser.
4-
import { Jimp } from "jimp/browser";
3+
import { Jimp } from "jimp";
54

65
export function GrayscaleExample() {
76
const [selectedFile, setSelectedFile] = useState("");

packages/docs/src/content/docs/guides/browser.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import { Code } from "@astrojs/starlight/components";
1010
Jimp can be used anywhere that javascript is supported. It can be used in the browser, in Node.js, or in a web worker.
1111

1212
Jimp comes with a pre-bundled browser version.
13-
To use it simply import `jimp/browser` instead.
13+
To use it simply import `jimp` instead.
1414

15-
> Note: Your bundler might do this automatically for you!
1615

1716
<br />
1817
<GrayscaleExample client:load />

packages/jimp/package.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,22 @@
9595
"exclude": [
9696
"**/*.test.ts"
9797
],
98+
"esmDialects": [
99+
"browser"
100+
],
98101
"exports": {
99102
"./package.json": "./package.json",
100103
".": "./src/index.ts",
101-
"./fonts": "./src/fonts.ts",
102-
"./browser": {
103-
"types": "./dist/esm/index.d.ts",
104-
"import": "./browser.js"
105-
}
104+
"./fonts": "./src/fonts.ts"
106105
}
107106
},
108107
"exports": {
109108
"./package.json": "./package.json",
110109
".": {
110+
"browser": {
111+
"types": "./dist/browser/index.d.ts",
112+
"default": "./dist/browser/index.js"
113+
},
111114
"import": {
112115
"types": "./dist/esm/index.d.ts",
113116
"default": "./dist/esm/index.js"
@@ -118,6 +121,10 @@
118121
}
119122
},
120123
"./fonts": {
124+
"browser": {
125+
"types": "./dist/browser/fonts.d.ts",
126+
"default": "./dist/browser/fonts.js"
127+
},
121128
"import": {
122129
"types": "./dist/esm/fonts.d.ts",
123130
"default": "./dist/esm/fonts.js"
@@ -126,10 +133,6 @@
126133
"types": "./dist/commonjs/fonts.d.ts",
127134
"default": "./dist/commonjs/fonts.js"
128135
}
129-
},
130-
"./browser": {
131-
"types": "./dist/esm/index.d.ts",
132-
"import": "./browser.js"
133136
}
134137
},
135138
"main": "./dist/commonjs/index.js",

packages/jimp/rollup.config.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ import alias from "@rollup/plugin-alias";
55
import nodePolyfills from "rollup-plugin-polyfill-node";
66
import inject from "@rollup/plugin-inject";
77
import terser from "@rollup/plugin-terser";
8+
import { dts } from "rollup-plugin-dts";
9+
10+
import { promises as fs } from "fs";
11+
12+
async function maybeUnlink(path) {
13+
try {
14+
await fs.unlink(path);
15+
} catch (error) {
16+
if (error.code !== "ENOENT") {
17+
throw error;
18+
}
19+
}
20+
}
21+
22+
// Remove tshy's output
23+
await maybeUnlink("dist/browser/index-browser.d.mts.map");
24+
await maybeUnlink("dist/browser/index-browser.mjs.map");
25+
await maybeUnlink("dist/browser/index.d.ts");
26+
await maybeUnlink("dist/browser/index.js");
827

928
function injectCodePlugin(code) {
1029
return {
@@ -62,11 +81,16 @@ export default [
6281
],
6382
output: [
6483
{
65-
file: `browser.js`,
84+
file: "dist/browser/index.js",
6685
format: "es",
6786
sourcemap: true,
6887
inlineDynamicImports: true,
6988
},
7089
],
7190
},
91+
{
92+
input: `src/index.ts`,
93+
output: [{ file: "dist/browser/index.d.ts", format: "es" }],
94+
plugins: [dts()],
95+
},
7296
];

packages/jimp/src/index-browser.mts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// A stub. The real build is done by rollup.

packages/jimp/tsconfig.docs.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["**/*.test.*"]
4+
}

0 commit comments

Comments
 (0)