Skip to content

Commit 304b206

Browse files
committed
v3.0.2 README update
1 parent 5760fa8 commit 304b206

7 files changed

Lines changed: 155 additions & 61 deletions

File tree

README.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ page in your application only or you want to place it somewhere in the UI where
122122

123123
## Getting Started
124124

125+
Make sure that everything is guarded by the NODE_ENV check so it doesn't break your production build if you installed it as a dev dependency!
126+
125127
To install and utilize Remix Development Tools, follow these steps:
126128

127129
1. Install the package via npm:
@@ -133,15 +135,32 @@ npm install remix-development-tools -D
133135
2. Add the following to your application `root.tsx` file:
134136

135137
```diff
136-
+ import rdtStylesheet from "remix-development-tools/index.css";
137-
+ import { withDevTools } from "remix-development-tools";
138-
138+
// Import styles
139+
+ import rdtStylesheet from "remix-development-tools/index.css";
139140
+ export const links: LinksFunction = () => [
141+
// export the stylesheet in development only
140142
+ process.env.NODE_ENV === "development" ? [{ rel: "stylesheet", href: rdtStylesheet }] : [],
141143
+ ]
142144

145+
+ let devTools = null;
146+
// This imports the dev tools only if you're in development
147+
+ if(process.env.NODE_ENV === 'development') {
148+
+ const { withDevTools } = await import("remix-development-tools");
149+
+ devTools = withDevTools
150+
+ }
151+
// Conditionally wraps the app with the dev tools
152+
+ export default devTools ? devTools(App) : App;
143153

144-
+ export default process.env.NODE_ENV === "development" ? withDevTools(App) : App;
154+
```
155+
If you're using CJS instead of ESM you can do the following instead:
156+
```diff
157+
158+
if(process.env.NODE_ENV === 'development') {
159+
- const { withDevTools } = await import("remix-development-tools");
160+
+ const { withDevTools } = require("remix-development-tools");
161+
devTools = withDevTools
162+
}
163+
export default devTools ? devTools(App) : App;
145164

146165
```
147166

@@ -151,30 +170,45 @@ If you want to add the server side logs and listeners you need to do one of the
151170

152171
### Custom server setup
153172

173+
Make sure that everything is guarded by the NODE_ENV check so it doesn't break your production build if you installed it as a dev dependency!
174+
154175
If you're running a custom server this is what you need to do:
155176
1. Wrap your build in your server file with `withServerDevTools` function. This takes an optional second parameter that allows you to configure it.
156177
2. Wrap your re-imported build too if you are in manual mode.
157178
3. You're done! Here is the example code:
158179

159-
```ts
160-
import { withServerDevTools, defineServerConfig } from 'remix-development-tools/server'
161-
// Allows you to define the configuration for the dev tools
162-
const devToolsConfig = defineServerConfig({
163-
//... your config here ...
164-
})
165-
166-
const build = await import(BUILD_PATH)
167-
// wrap the build with the wrapper provided by the package
168-
let devBuild = withServerDevTools(build, devToolsConfig)
169-
170-
// .... somewhere later in your code ...
171-
// This makes sure the build is wrapped on reload, you will need this if you're running with the --manual flag
172-
async function reloadBuild() {
173-
devBuild = await import(`${BUILD_PATH}?update=${Date.now()}`)
174-
devBuild = withServerDevTools(devBuild, devToolsConfig)
175-
broadcastDevReady(devBuild)
180+
```ts
181+
// Somewhere in your server.ts file
182+
const build = await import(BUILD_PATH)
183+
let devBuild = build
184+
let devToolsConfig = null;
185+
// Make sure you guard this with NODE_ENV check
186+
if(process.env.NODE_ENV === 'development') {
187+
const { withServerDevTools, defineServerConfig } = await import("remix-development-tools/server");
188+
// Allows you to define the configuration for the dev tools
189+
devToolsConfig = defineServerConfig({
190+
//... your config here ...
191+
})
192+
// wrap the build with the dev tools
193+
devBuild = withServerDevTools(build, devToolsConfig)
194+
}
195+
// Make sure you guard this with NODE_ENV check
196+
if(process.env.NODE_ENV === "development"){
197+
// .... somewhere later in your code ...
198+
// This makes sure the build is wrapped on reload, you will need this if you're running with the --manual flag
199+
async function reloadBuild() {
200+
devBuild = await import(`${BUILD_PATH}?update=${Date.now()}`)
201+
// wrap the build with dev tools on re-import
202+
devBuild = withServerDevTools(devBuild, devToolsConfig)
203+
broadcastDevReady(devBuild)
204+
}
176205
}
177206
```
207+
If you're using a CJS custom server you can replace the following lines:
208+
```diff
209+
- const { withServerDevTools, defineServerConfig } = await import("remix-development-tools/server");
210+
+ const { withServerDevTools, defineServerConfig } = require("remix-development-tools/server");
211+
```
178212

179213
### CJS remix server setup (remix run server started by remix dev)
180214

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "remix-development-tools",
33
"description": "Remix development tools.",
44
"author": "Alem Tuzlak",
5-
"version": "3.0.1",
5+
"version": "3.0.2",
66
"license": "MIT",
77
"keywords": [
88
"remix",

src/test-apps/cjs-app/app/routes/_index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ActionFunctionArgs } from "@remix-run/node";
22
import { json, redirect, type LoaderFunctionArgs, defer } from "@remix-run/node";
33
import type { MetaFunction } from "@remix-run/node";
44
import { Link, useFetcher, useSubmit } from "@remix-run/react";
5+
import { Button } from "components/Button";
56

67
export const meta: MetaFunction = () => {
78
return [
@@ -11,7 +12,7 @@ export const meta: MetaFunction = () => {
1112
};
1213

1314
export const loader = async ({ request }: LoaderFunctionArgs) => {
14-
throw redirect("/dashboard");
15+
1516
const test = new Promise((resolve) => {
1617
setTimeout(() => {
1718
resolve("test");
@@ -23,7 +24,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2324
export const action = async ({ request }: ActionFunctionArgs) => {
2425
return redirect("/login");
2526
};
26-
27+
2728
export default function Index() {
2829
const lFetcher = useFetcher();
2930
const pFetcher = useFetcher();
@@ -33,11 +34,14 @@ export default function Index() {
3334
return (
3435
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
3536
<h1>Welcome to Remix</h1>
36-
<button
37-
onClick={() => lFetcher.submit(null, { method: "get", action: "/" })}
37+
<Button
38+
onClick={(e) => {
39+
console.log(e);
40+
lFetcher.submit(null, { method: "get", action: "/" })
41+
}}
3842
>
3943
FETCHER Loader
40-
</button>
44+
</Button>
4145
<button
4246
onClick={() => pFetcher.submit(data, { method: "POST", action: "/" })}
4347
>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReactNode } from "react";
2+
3+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
4+
children: ReactNode
5+
}
6+
7+
const Button = ({ children, ...props }: ButtonProps) => {
8+
return (
9+
<button {...props}>
10+
{children}
11+
</button>
12+
);
13+
}
14+
15+
export { Button };

0 commit comments

Comments
 (0)