diff --git a/server/index.ts b/server/index.ts index c3382ec5..a51a8181 100644 --- a/server/index.ts +++ b/server/index.ts @@ -13,7 +13,6 @@ import { import { wrapExpressCreateRequestHandler } from '@sentry/remix' import address from 'address' import chalk from 'chalk' -import chokidar from 'chokidar' import closeWithGrace from 'close-with-grace' import compression from 'compression' import express from 'express' @@ -22,10 +21,6 @@ import getPort, { portNumbers } from 'get-port' import helmet from 'helmet' import morgan from 'morgan' -// @ts-ignore - this file may not exist if you haven't built yet, but it will -// definitely exist by the time the dev or prod server actually runs. -import * as remixBuild from '#build/index.js' - installGlobals() const MODE = process.env.NODE_ENV @@ -35,8 +30,13 @@ const createRequestHandler = wrapExpressCreateRequestHandler( ) const BUILD_PATH = '../build/index.js' +const WATCH_PATH = '../build/version.txt' -const build = remixBuild as unknown as ServerBuild +/** + * Initial build + * @type {ServerBuild} + */ +const build = await import(BUILD_PATH) let devBuild = build const app = express() @@ -262,8 +262,14 @@ if (MODE === 'development') { broadcastDevReady(devBuild) } + // We'll import chokidar here so doesn't get bundled in production. + const chokidar = await import('chokidar') + const dirname = path.dirname(fileURLToPath(import.meta.url)) - const watchPath = path.join(dirname, BUILD_PATH).replace(/\\/g, '/') - const watcher = chokidar.watch(watchPath, { ignoreInitial: true }) - watcher.on('all', reloadBuild) + const watchPath = path.join(dirname, WATCH_PATH).replace(/\\/g, '/') + + chokidar + .watch(watchPath, { ignoreInitial: true }) + .on('add', reloadBuild) + .on('change', reloadBuild) }