Skip to content

Commit 0af0182

Browse files
fix browser build
1 parent 97deb26 commit 0af0182

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

packages/docs/src/content/docs/index.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ hero:
88
file: ../../assets/image.png
99
actions:
1010
- text: Read the docs
11-
link: /guides/getting-started/
11+
link: /jimp/guides/getting-started/
1212
icon: right-arrow
1313
variant: primary
1414
- text: GitHub
@@ -63,6 +63,6 @@ Load an image, manipulate it, and save it.
6363
</Steps>
6464

6565
<CardGrid>
66-
<LinkCard title="Getting Started" href="/guides/getting-started/" />
67-
<LinkCard title="API Reference" href="/api/jimp/classes/jimp/" />
66+
<LinkCard title="Getting Started" href="/jimp/guides/getting-started/" />
67+
<LinkCard title="API Reference" href="/jimp/api/jimp/classes/jimp/" />
6868
</CardGrid>

packages/jimp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@rollup/plugin-terser": "^0.4.4",
7676
"@vitest/browser": "^1.4.0",
7777
"eslint": "^8.57.0",
78+
"node-self": "^1.0.2",
7879
"path-browserify": "^1.0.1",
7980
"rollup": "^4.14.1",
8081
"rollup-plugin-dts": "^6.1.0",

packages/jimp/rollup.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,45 @@ import nodePolyfills from "rollup-plugin-polyfill-node";
66
import inject from "@rollup/plugin-inject";
77
import terser from "@rollup/plugin-terser";
88

9+
function injectCodePlugin(code) {
10+
return {
11+
name: "inject-code",
12+
transform(src, id) {
13+
if (id.endsWith("jimp/src/index.ts")) {
14+
const injectedCode = `${code}\n${src}`;
15+
const lines = code.split("\n");
16+
const injectedLines = injectedCode.split("\n");
17+
const mappings = [];
18+
19+
for (let i = 0; i < injectedLines.length; i++) {
20+
mappings.push([i, 0, 0, 0]);
21+
}
22+
23+
for (let i = 0; i < lines.length; i++) {
24+
mappings.push([i + injectedLines.length, 0, i, 0]);
25+
}
26+
27+
return {
28+
code: injectedCode,
29+
map: {
30+
version: 3,
31+
file: id,
32+
sources: [id],
33+
sourcesContent: [code],
34+
names: [],
35+
mappings: mappings.map((mapping) => mapping.join(",")).join(";"),
36+
},
37+
};
38+
}
39+
},
40+
};
41+
}
42+
943
export default [
1044
{
1145
input: `src/index.ts`,
1246
plugins: [
47+
injectCodePlugin('import "node-self"'),
1348
esbuild(),
1449

1550
// Polyfill Node.js builtins

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)