headplane/server/dev.mjs

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-12-23 10:27:05 -05:00
// This is a polyglot entrypoint for Headplane when running in development
// It does some silly magic to load the vite config, set some globals that
// are required to function, and create the vite development server.
2024-12-31 10:30:14 +05:30
import { createServer } from 'vite';
import { env, exit } from 'node:process';
import { log } from './utils.mjs';
2024-12-23 10:27:05 -05:00
2024-12-31 10:30:14 +05:30
log('DEVX', 'INFO', 'This script is only intended for development');
env.NODE_ENV = 'development';
2024-12-23 10:27:05 -05:00
// The production entrypoint uses a global called "PREFIX" to determine
// what route the application is being served at and a global called "BUILD"
// to determine the Remix handler. We need to set these globals here so that
// the development server can function correctly and override the production
// values.
2024-12-31 10:30:14 +05:30
log('DEVX', 'INFO', 'Creating Vite Development Server');
2024-12-23 10:27:05 -05:00
const server = await createServer({
server: {
2024-12-31 10:30:14 +05:30
middlewareMode: true,
},
});
2024-12-23 10:27:05 -05:00
// This entrypoint is defined in the documentation to load the server
2024-12-31 10:30:14 +05:30
const build = await server.ssrLoadModule('virtual:react-router/server-build');
2024-12-23 10:27:05 -05:00
// We already handle this logic in the Vite configuration
2024-12-31 10:30:14 +05:30
global.PREFIX = server.config.base.slice(0, -1);
global.BUILD = build;
global.MODE = 'development';
global.MIDDLEWARE = server.middlewares;
2024-12-23 10:27:05 -05:00
2024-12-31 10:30:14 +05:30
await import('./prod.mjs');