diff --git a/packages/cli/src/commands/buildHandler.js b/packages/cli/src/commands/buildHandler.js index 411d1a318662..f6bb7a08029f 100644 --- a/packages/cli/src/commands/buildHandler.js +++ b/packages/cli/src/commands/buildHandler.js @@ -11,7 +11,6 @@ import { buildApi } from '@redwoodjs/internal/dist/build/api' import { loadAndValidateSdls } from '@redwoodjs/internal/dist/validateSchema' import { detectPrerenderRoutes } from '@redwoodjs/prerender/detection' import { timedTelemetry } from '@redwoodjs/telemetry' -import { buildFeServer } from '@redwoodjs/vite' import { getPaths, getConfig } from '../lib' import { generatePrismaCommand } from '../lib/generatePrismaClient' @@ -106,32 +105,26 @@ export const handler = async ({ title: 'Building Web...', task: async () => { if (getConfig().web.bundler !== 'webpack') { - if (!getConfig().experimental?.streamingSsr?.enabled) { - // @NOTE: we're using the vite build command here, instead of the - // buildWeb function directly because we want the process.cwd to be - // the web directory, not the root of the project. - // This is important for postcss/tailwind to work correctly - // Having a separate binary lets us contain the change of cwd to that - // process only. If we changed cwd here, or in the buildWeb function, - // it could affect other things that run in parallel while building. - // We don't have any parallel tasks right now, but someone might add - // one in the future as a performance optimization. - await execa(`yarn rw-vite-build --webDir="${rwjsPaths.web.base}"`, { + // @NOTE: we're using the vite build command here, instead of the + // buildWeb function directly because we want the process.cwd to be + // the web directory, not the root of the project. + // This is important for postcss/tailwind to work correctly + // Having a separate binary lets us contain the change of cwd to that + // process only. If we changed cwd here, or in the buildWeb function, + // it could affect other things that run in parallel while building. + // We don't have any parallel tasks right now, but someone might add + // one in the future as a performance optimization. + await execa( + `yarn rw-vite-build --webDir="${rwjsPaths.web.base}" --verbose=${verbose}`, + { stdio: verbose ? 'inherit' : 'pipe', shell: true, - // This is needed for yarn to find the rw-vite-build binary + // `cwd` is needed for yarn to find the rw-vite-build binary // It won't change process.cwd for anything else here, in this // process cwd: rwjsPaths.web.base, - }) - } else { - // TODO (STREAMING) we need to contain this in a separate binary - process.chdir(rwjsPaths.web.base) - - // TODO (STREAMING) we need to use a binary here, so the the cwd is correct - // Should merge this with the existing rw-vite-build binary - await buildFeServer({ verbose }) - } + } + ) } else { await execa( `yarn cross-env NODE_ENV=production webpack --config ${require.resolve( diff --git a/packages/vite/bins/rw-vite-build.mjs b/packages/vite/bins/rw-vite-build.mjs index 9710a1c3c076..c4380ada75ed 100755 --- a/packages/vite/bins/rw-vite-build.mjs +++ b/packages/vite/bins/rw-vite-build.mjs @@ -3,12 +3,14 @@ import fs from 'node:fs' import yargsParser from 'yargs-parser' import { buildWeb } from '@redwoodjs/internal/dist/build/web.js' -import projectConfig from '@redwoodjs/project-config' +import { getConfig, getPaths } from '@redwoodjs/project-config' +import { buildFeServer } from '@redwoodjs/vite/dist/buildFeServer.js' -const rwPaths = projectConfig.getPaths() +const rwPaths = getPaths() -const { webDir } = yargsParser(process.argv.slice(2), { +const { webDir, verbose } = yargsParser(process.argv.slice(2), { string: ['webDir'], + boolean: ['verbose'], }) if (!webDir) { @@ -43,11 +45,13 @@ const buildWebSide = async (webDir) => { process.chdir(webDir) process.env.NODE_ENV = 'production' - // Right now, the buildWeb function looks up the config file from project-config - // In the future, if we have multiple web spaces we could pass in the cwd here - buildWeb({ - verbose: true, - }) + if (getConfig().experimental?.streamingSsr?.enabled) { + await buildFeServer({ verbose }) + } else { + // Right now, the buildWeb function looks up the config file from project-config + // In the future, if we have multiple web spaces we could pass in the cwd here + buildWeb({ verbose }) + } } buildWebSide(webDir) diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index 37ae566af730..939c81b4a350 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -214,5 +214,3 @@ export default function redwoodPluginVite(): PluginOption[] { }), ] } - -export { buildFeServer } from './buildFeServer'