Skip to content

Commit

Permalink
Reduce sourcemap builds and minify
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikesymmetry committed May 16, 2024
1 parent 46bb14f commit ab0a81b
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 47 deletions.
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
# Callsmith

> GraphQL has GraphiQL, NextJS has Callsmith.
A generative interface for calling API routes on NextJS App Router.
A generative interface for calling API routes on NextJS App Router. Inspired by GraphiQL, Callsmith's goal is to be the easiest way to call your API for development and testing purposes.

## Install

```bash
npm i callsmith
```

## Add client component

A workaround is in progress for this, but to make App Router happy, we need to use our `Callsmith` component with the `"use client"` directive in our page.

```jsx
"use client";
export { Callsmith } from "callsmith/client";
```

## Add page

Note that this needs to be a server component so that `getAppRoutes` can leverage the local filesystem to determine the available routes and methods.
Note that this page needs to be rendered server-side to leverage the local filesystem for determining available API routes.

```jsx
import { Callsmith } from "callsmith/client";
import { getAppRoutes } from "callsmith/server";
import { Callsmith } from "./callsmith";

export default function Page() {
return <Callsmith nodes={getAppRoutes()} />;
Expand Down
81 changes: 67 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "callsmith",
"version": "0.0.7",
"version": "0.0.9",
"exports": {
"./client": {
"import": "./dist/client.es.js",
Expand All @@ -17,6 +17,10 @@
"dist"
],
"private": false,
"repository": {
"type": "git",
"url": "git+https://github.com/ilikesymmetry/callsmith.git"
},
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down Expand Up @@ -70,6 +74,7 @@
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-styles": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"tailwind-merge": "^2.3.0",
"tailwindcss": "^3.4.3",
"tailwindcss-animate": "^1.0.7",
Expand Down
8 changes: 4 additions & 4 deletions packages/test-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"callsmith": "^0.0.7",
"callsmith": "^0.0.9",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18"
Expand Down
5 changes: 0 additions & 5 deletions packages/test-app/src/app/callsmith.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions packages/test-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import { Callsmith } from "callsmith/client";
// import { getAppRoutes } from "callsmith/server";
import { Callsmith } from "../../../../dist/client";
import { getAppRoutes } from "../../../../dist/server";
import { Callsmith } from "callsmith/client";
import { getAppRoutes } from "callsmith/server";
// import { Callsmith } from "../../../../dist/client";
// import { getAppRoutes } from "../../../../dist/server";

export default function Page() {
return <Callsmith nodes={getAppRoutes()} />;
Expand Down
2 changes: 1 addition & 1 deletion packages/test-app/src/app/routes/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export async function GET() {}
// export async function GET() {}
8 changes: 5 additions & 3 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import commonjs from "@rollup/plugin-commonjs";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import replace from "@rollup/plugin-replace";
import styles from "rollup-plugin-styles";
import { terser } from "rollup-plugin-terser";
import addUseClient from "./rollup-plugin-use-client.js";

import { fileURLToPath } from "url";
Expand All @@ -24,14 +25,14 @@ const config = {
{
dir: "dist",
format: "cjs",
sourcemap: true,
sourcemap: false,
entryFileNames: "[name].js",
assetFileNames: "[name][extname]",
},
{
dir: "dist",
format: "es",
sourcemap: true,
sourcemap: false,
entryFileNames: "[name].es.js",
},
],
Expand Down Expand Up @@ -78,9 +79,10 @@ const config = {
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
terser(),
addUseClient(),
],
external: ["react", "react-dom", "next"],
external: ["react", "react-dom", "next", "tailwindcss"],
};

export default config;

0 comments on commit ab0a81b

Please sign in to comment.