Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve bundler integration #1321

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ export default defineConfig({
"../../packages/jimp/src/index.ts",
"../../packages/jimp/src/fonts.ts",
],
tsconfig: "../../packages/jimp/tsconfig.json",
tsconfig: "../../packages/jimp/tsconfig.docs.json",
typeDoc: {
groupOrder: ["Classes", "Functions", "Enumerations", "Variables"],
sort: ["static-first", "alphabetical"],
plugin: [
path.join(
path.dirname(import.meta.url).replace("file:", ""),
"./src/typedoc-plugin.js",
"./src/typedoc-plugin.js"
),
"typedoc-plugin-zod",
path.join(
path.dirname(import.meta.url).replace("file:", ""),
"./src/typedoc-zod-extended.js",
"./src/typedoc-zod-extended.js"
),
],
},
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/src/components/grayscale-example.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState } from "react";

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

export function GrayscaleExample() {
const [selectedFile, setSelectedFile] = useState("");
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/src/content/docs/guides/browser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { Code } from "@astrojs/starlight/components";
Jimp can be used anywhere that javascript is supported. It can be used in the browser, in Node.js, or in a web worker.

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

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

<br />
<GrayscaleExample client:load />
Expand Down
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.
4 changes: 4 additions & 0 deletions packages/jimp/tsconfig.docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.test.*"]
}
Loading