@@ -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+
125127To install and utilize Remix Development Tools, follow these steps:
126128
1271291 . Install the package via npm:
@@ -133,15 +135,32 @@ npm install remix-development-tools -D
1331352 . 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+
154175If you're running a custom server this is what you need to do:
1551761 . Wrap your build in your server file with ` withServerDevTools ` function. This takes an optional second parameter that allows you to configure it.
1561772 . Wrap your re-imported build too if you are in manual mode.
1571783 . 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
0 commit comments