Skip to content

Commit cea2562

Browse files
authored
Merge pull request #5 from gadget-inc/change-widgets-location-default
Change widgets location default
2 parents 561ab6a + 2b72eb7 commit cea2562

File tree

22 files changed

+25
-25
lines changed

22 files changed

+25
-25
lines changed

AGENTS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This plugin solves these problems by:
4444

4545
```
4646
your-project/
47-
├── web/chatgpt-widgets/ # Widget components directory (configurable)
47+
├── web/chatgpt/ # Widget components directory (configurable)
4848
│ ├── root.tsx # Optional: Root layout wrapper for all widgets
4949
│ ├── MyWidget.tsx # Individual widget components
5050
│ └── AnotherWidget.tsx
@@ -126,8 +126,8 @@ import { getWidgets } from "vite-plugin-chatgpt-widgets";
126126
// Determine mode and get widgets
127127
const widgets =
128128
process.env.NODE_ENV === "production"
129-
? await getWidgets("web/chatgpt-widgets", { manifestPath: "dist/.vite/manifest.json" })
130-
: await getWidgets("web/chatgpt-widgets", { devServer: viteDevServerInstance });
129+
? await getWidgets("web/chatgpt", { manifestPath: "dist/.vite/manifest.json" })
130+
: await getWidgets("web/chatgpt", { devServer: viteDevServerInstance });
131131

132132
// Register each as an MCP resource
133133
for (const widget of widgets) {
@@ -153,7 +153,7 @@ for (const widget of widgets) {
153153
### Widget Component Pattern
154154

155155
```tsx
156-
// web/chatgpt-widgets/DataDisplay.tsx
156+
// web/chatgpt/DataDisplay.tsx
157157
export default function DataDisplay() {
158158
// Access tool output from ChatGPT
159159
const data = window.openai?.tool_output;
@@ -165,7 +165,7 @@ export default function DataDisplay() {
165165
### Root Layout Pattern
166166

167167
```tsx
168-
// web/chatgpt-widgets/root.tsx
168+
// web/chatgpt/root.tsx
169169
import { ThemeProvider } from "./theme";
170170

171171
export default function RootLayout({ children }: { children: React.ReactNode }) {

Readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { chatGPTWidgetPlugin } from "vite-plugin-chatgpt-widgets";
2323
export default defineConfig({
2424
plugins: [
2525
chatGPTWidgetPlugin({
26-
widgetsDir: "web/chatgpt-widgets", // default: 'web/chatgpt-widgets'
26+
widgetsDir: "web/chatgpt", // default: 'web/chatgpt'
2727
baseUrl: "https://example.com", // if not using a vite `base`, this is required because the chatgpt iframe is sandboxed and absolute URL links are required
2828
}),
2929
],
@@ -44,12 +44,12 @@ export default defineConfig({
4444
Create React components in your widgets directory:
4545

4646
```tsx
47-
// in web/chatgpt-widgets/Hello.tsx
47+
// in web/chatgpt/Hello.tsx
4848
export default function Hello() {
4949
return <div>Hello from ChatGPT Widget!</div>;
5050
}
5151

52-
// in web/chatgpt-widgets/ListFoobars.tsx
52+
// in web/chatgpt/ListFoobars.tsx
5353
export default function ListFoobars() {
5454
return (
5555
<ul>
@@ -66,7 +66,7 @@ export default function ListFoobars() {
6666
You can optionally create a root layout component that will wrap all widgets. If a file named `root.tsx` (or `root.ts`, `root.jsx`, `root.js`) exists in the widgets directory, it will automatically wrap all other widget components:
6767

6868
```tsx
69-
// web/chatgpt-widgets/root.tsx
69+
// web/chatgpt/root.tsx
7070
export default function RootLayout({ children }: { children: React.ReactNode }) {
7171
return (
7272
<SomeProvider>
@@ -91,10 +91,10 @@ After setting up the plugin and writing some widgets, you need to expose the wid
9191
import { getWidgets } from "vite-plugin-chatgpt-widgets";
9292

9393
// In development, pass the Vite dev server instance from wherever you can get it
94-
const widgets = await getWidgets("web/chatgpt-widgets", viteDevServer);
94+
const widgets = await getWidgets("web/chatgpt", viteDevServer);
9595

9696
// In production, pass a path to the vite manifest, where we'll load precompiled versions from
97-
const widgets = await getWidgets("web/chatgpt-widgets", {
97+
const widgets = await getWidgets("web/chatgpt", {
9898
manifestPath: "dist/.vite/manifest.json",
9999
});
100100

@@ -184,7 +184,7 @@ The Vite plugin.
184184

185185
**Options:**
186186

187-
- `widgetsDir` (string, optional): Directory containing widget components. Default: `'web/chatgpt-widgets'`
187+
- `widgetsDir` (string, optional): Directory containing widget components. Default: `'web/chatgpt'`
188188
- `baseUrl` (string, optional): Base URL for widget assets. Required if Vite's `base` config is not an absolute URL and you need fully qualified URLs for sandboxed iframes. Should include protocol and domain (e.g., `"https://example.com"`). Note: Does not require trailing slash.
189189

190190
### `getWidgets(widgetsDir, viteHandle)`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-chatgpt-widgets",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"files": [
55
"Readme.md",
66
"dist/**/*"

spec/fixtureDirs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import * as path from "path";
22

33
export const FIXTURE_DIR = path.resolve(__dirname, "fixtures/test-project");
4-
export const WIDGETS_DIR = path.join(FIXTURE_DIR, "web/chatgpt-widgets");
4+
export const WIDGETS_DIR = path.join(FIXTURE_DIR, "web/chatgpt");
55
export const BUILD_DIR = path.join(FIXTURE_DIR, "dist");
66
export const MANIFEST_PATH = path.join(BUILD_DIR, ".vite/manifest.json");
77
export const FIXTURE_WITH_ROOT_DIR = path.resolve(__dirname, "fixtures/test-project-with-root");
8-
export const WIDGETS_WITH_ROOT_DIR = path.join(FIXTURE_WITH_ROOT_DIR, "web/chatgpt-widgets");
8+
export const WIDGETS_WITH_ROOT_DIR = path.join(FIXTURE_WITH_ROOT_DIR, "web/chatgpt");
99
export const BUILD_WITH_ROOT_DIR = path.join(FIXTURE_WITH_ROOT_DIR, "dist");
1010
export const MANIFEST_WITH_ROOT_PATH = path.join(BUILD_WITH_ROOT_DIR, ".vite/manifest.json");
1111
export const FIXTURE_REACT_ROUTER_DIR = path.resolve(__dirname, "fixtures/test-project-react-router");
12-
export const WIDGETS_REACT_ROUTER_DIR = path.join(FIXTURE_REACT_ROUTER_DIR, "web/chatgpt-widgets");
12+
export const WIDGETS_REACT_ROUTER_DIR = path.join(FIXTURE_REACT_ROUTER_DIR, "web/chatgpt");
1313
export const BUILD_REACT_ROUTER_DIR = path.join(FIXTURE_REACT_ROUTER_DIR, "build/client");
1414
export const MANIFEST_REACT_ROUTER_PATH = path.join(BUILD_REACT_ROUTER_DIR, ".vite/manifest.json");
1515
export const FIXTURE_PLAIN_REACT_DIR = path.resolve(__dirname, "fixtures/test-project-plain-react");
16-
export const WIDGETS_PLAIN_REACT_DIR = path.join(FIXTURE_PLAIN_REACT_DIR, "web/chatgpt-widgets");
16+
export const WIDGETS_PLAIN_REACT_DIR = path.join(FIXTURE_PLAIN_REACT_DIR, "web/chatgpt");
1717
export const BUILD_PLAIN_REACT_DIR = path.join(FIXTURE_PLAIN_REACT_DIR, "dist");
1818
export const MANIFEST_PLAIN_REACT_PATH = path.join(BUILD_PLAIN_REACT_DIR, ".vite/manifest.json");

spec/fixtures/test-project-plain-react/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
plugins: [
1010
react(),
1111
chatGPTWidgetPlugin({
12-
widgetsDir: "web/chatgpt-widgets",
12+
widgetsDir: "web/chatgpt",
1313
baseUrl: "https://example.com",
1414
}),
1515
],

spec/fixtures/test-project-react-router/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
plugins: [
1010
reactRouter(),
1111
chatGPTWidgetPlugin({
12-
widgetsDir: "web/chatgpt-widgets",
12+
widgetsDir: "web/chatgpt",
1313
baseUrl: "https://example.com",
1414
}),
1515
],

0 commit comments

Comments
 (0)