From 43ecd811ca69121c5f1e395096848f6cdc72b110 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 26 Jan 2024 10:49:21 -0800 Subject: [PATCH] fix: deploy with vercel --- remix.config.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/remix.config.js b/remix.config.js index 69775d6a..d6ced029 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,4 +1,4 @@ -const { createRoutesFromFolders } = require('@remix-run/v1-route-convention'); +// const { createRoutesFromFolders } = require('@remix-run/v1-route-convention'); /** * @type {import('@remix-run/dev').AppConfig} @@ -8,6 +8,14 @@ const cloudflarePagesConfig = { server: './server-cloudflare-pages.js', ignoredRouteFiles: ['**/.*'], }; +/** + * @type {import('@remix-run/dev').AppConfig} + */ +const vercelConfig = { + // serverBuildTarget: 'netlify', + // server: './server-netlify.js', + ignoredRouteFiles: ['**/.*'], +}; /** * @type {import('@remix-run/dev').AppConfig} */ @@ -27,10 +35,10 @@ const devConfig = { future: { v2_dev: true, }, - routes(defineRoutes) { - // uses the v1 convention, works in v1.15+ and v2 - return createRoutesFromFolders(defineRoutes); - }, + // routes(defineRoutes) { + // // uses the v1 convention, works in v1.15+ and v2 + // return createRoutesFromFolders(defineRoutes); + // }, }; /** @@ -44,14 +52,26 @@ const buildConfig = { ignoredRouteFiles: ['.*'], }; +// function selectConfig() { +// if (!['development', 'production'].includes(process.env.NODE_ENV)) +// throw `Unknown NODE_ENV: ${process.env.NODE_ENV}`; +// if (process.env.NODE_ENV === 'development') return devConfig; +// if (!process.env.CF_PAGES && !process.env.NETLIFY) return buildConfig; +// if (process.env.CF_PAGES) return cloudflarePagesConfig; +// if (process.env.NETLIFY) return netlifyConfig; +// throw `Cannot select config`; +// } + function selectConfig() { - if (!['development', 'production'].includes(process.env.NODE_ENV)) - throw `Unknown NODE_ENV: ${process.env.NODE_ENV}`; - if (process.env.NODE_ENV === 'development') return devConfig; - if (!process.env.CF_PAGES && !process.env.NETLIFY) return buildConfig; + const ENV = process.env?.NODE_ENV || process.env?.VERCEL_ENV; + if (!['preview', 'development', 'production'].includes(ENV)) + throw new Error(`Unknown ENV: ${ENV}`); if (process.env.CF_PAGES) return cloudflarePagesConfig; if (process.env.NETLIFY) return netlifyConfig; - throw `Cannot select config`; + if (process.env.VERCEL) return vercelConfig; + if (ENV === 'development') return devConfig; + if (!process.env.CF_PAGES && !process.env.NETLIFY) return buildConfig; + throw new Error(`Cannot select config`); } module.exports = selectConfig();