Skip to content

Commit

Permalink
Use existing rw-vite-build bin for SSR as well (#8806)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jul 1, 2023
1 parent 7c1029d commit 8b2a566
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
37 changes: 15 additions & 22 deletions packages/cli/src/commands/buildHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 12 additions & 8 deletions packages/vite/bins/rw-vite-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
2 changes: 0 additions & 2 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,3 @@ export default function redwoodPluginVite(): PluginOption[] {
}),
]
}

export { buildFeServer } from './buildFeServer'

0 comments on commit 8b2a566

Please sign in to comment.