From a75a499ca7d31dc155a27e5fce763782d806f259 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 28 Jun 2023 19:12:56 -0700 Subject: [PATCH 1/2] fix(v6): custom web index is webpack only --- docs/docs/cli-commands.md | 7 +++++++ docs/docs/custom-web-index.md | 9 +++++++++ .../setup/custom-web-index/custom-web-index-handler.js | 5 +++++ .../commands/setup/custom-web-index/custom-web-index.js | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/docs/cli-commands.md b/docs/docs/cli-commands.md index 25a22a397d84..c6fa2b18688c 100644 --- a/docs/docs/cli-commands.md +++ b/docs/docs/cli-commands.md @@ -1779,6 +1779,13 @@ yarn redwood setup cache ### setup custom-web-index +:::caution This command only applies to projects using Webpack + +As of v6, all Redwood projects use Vite by default. +When switching projects to Vite, we made the decision to add the the entry file, `web/src/entry.client.{jsx,tsx}`, back to projects. + +::: + Redwood automatically mounts your `` to the DOM, but if you want to customize how that happens, you can use this setup command to generate an `index.js` file in `web/src`. ``` diff --git a/docs/docs/custom-web-index.md b/docs/docs/custom-web-index.md index a713be6282bf..775fa2c891a8 100644 --- a/docs/docs/custom-web-index.md +++ b/docs/docs/custom-web-index.md @@ -4,6 +4,15 @@ description: Change how App mounts to the DOM # Custom Web Index +:::caution This doc only applies to projects using Webpack + +As of v6, all Redwood projects use Vite by default. +When switching projects to Vite, we made the decision to add the the entry file, `web/src/entry.client.{jsx,tsx}`, back to projects. + +If you're using Webpack, this is all still applicable—keep reading. + +::: + You may have noticed that there's no call to `ReactDOM.render` in your Redwood app. That's because Redwood automatically mounts the `App` component in `web/src/App.js` to the DOM. But if you need to customize how this happens, you can provide a file named `index.js` in `web/src` and Redwood will use that instead. diff --git a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js index 4dfc85b05beb..b5b6c5ac1f51 100644 --- a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js +++ b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js @@ -10,6 +10,11 @@ import { getPaths, writeFile } from '../../../lib' import c from '../../../lib/colors' export const handler = async ({ force }) => { + if (getPaths().web.viteConfig) { + console.log('This command only applies to projects using webpack') + return + } + const tasks = new Listr( [ { diff --git a/packages/cli/src/commands/setup/custom-web-index/custom-web-index.js b/packages/cli/src/commands/setup/custom-web-index/custom-web-index.js index 73d05f3bafc2..e49709bc684c 100644 --- a/packages/cli/src/commands/setup/custom-web-index/custom-web-index.js +++ b/packages/cli/src/commands/setup/custom-web-index/custom-web-index.js @@ -3,7 +3,7 @@ import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers' export const command = 'custom-web-index' export const description = - 'Set up a custom index.js file, so you can customise how Redwood web is mounted in your browser' + 'Set up a custom index.js file, so you can customise how Redwood web is mounted in your browser (webpack only)' export const builder = (yargs) => { yargs.option('force', { From 483f2cf55a168f49f46387a6d1c0dc1597a3e2a0 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 28 Jun 2023 20:10:19 -0700 Subject: [PATCH 2/2] add color --- .../setup/custom-web-index/custom-web-index-handler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js index b5b6c5ac1f51..4f14f0db3d63 100644 --- a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js +++ b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js @@ -11,7 +11,9 @@ import c from '../../../lib/colors' export const handler = async ({ force }) => { if (getPaths().web.viteConfig) { - console.log('This command only applies to projects using webpack') + console.warn( + c.warning('Warning: This command only applies to projects using webpack') + ) return }