From 75c96415ad20c593d8972f0f4caa1aa27c0768a3 Mon Sep 17 00:00:00 2001 From: Mayke Freitas Date: Thu, 10 Nov 2022 15:50:04 -0300 Subject: [PATCH] allowing extra vite config --- package.json | 2 +- src/vite.ts | 52 +++++++++++++++++++++++++--------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index a0c59f7..931c1a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "remix-vite", - "version": "0.2.1", + "version": "0.2.2", "description": "Static file serving and directory listing", "keywords": [ "remix", diff --git a/src/vite.ts b/src/vite.ts index 29d7efe..a09af31 100644 --- a/src/vite.ts +++ b/src/vite.ts @@ -1,4 +1,4 @@ -import { createServer } from 'vite'; +import { createServer, mergeConfig } from 'vite'; import vitePluginReact from '@vitejs/plugin-react'; import tsconfigPaths from 'vite-tsconfig-paths'; import { getHmrFixPlugin } from './plugins/hmr-fix'; @@ -7,13 +7,9 @@ import { getRemixPlugin } from './plugins/remix'; import { getTransformPlugin } from './plugins/transform'; import { SERVER_ENTRY_ID } from './constants'; import { checkVersion } from './utils/version'; -import type { ViteDevServer, ServerOptions } from 'vite'; +import type { ViteDevServer, UserConfig } from 'vite'; import type { ServerBuild } from '@remix-run/server-runtime'; -export interface RemixViteServerOptions { - serverOptions?: ServerOptions; -} - /** * Get Remix build */ @@ -28,9 +24,7 @@ export const getRemixViteBuild = async (viteDevServer: ViteDevServer) => { /** * Create remix-vite dev server */ -export const createRemixViteDevServer = async ( - options?: RemixViteServerOptions, -) => { +export const createRemixViteDevServer = async (config?: UserConfig) => { await checkVersion(); const remixPlugin = await getRemixPlugin(); @@ -41,23 +35,27 @@ export const createRemixViteDevServer = async ( // Create Vite server in middleware mode and configure the app type as // 'custom', disabling Vite's own HTML serving logic so parent server // can take control - return createServer({ - server: { - fs: { - strict: false, + return createServer( + mergeConfig( + { + server: { + fs: { + strict: false, + }, + cors: true, + middlewareMode: true, + }, + plugins: [ + tsconfigPaths(), + remixInject, + remixPlugin, + remixTransformPlugin, + vitePluginReact(), + remixHmrFix, + ], + appType: 'custom', }, - cors: true, - ...options?.serverOptions, - middlewareMode: true, - }, - plugins: [ - tsconfigPaths(), - remixInject, - remixPlugin, - remixTransformPlugin, - vitePluginReact(), - remixHmrFix, - ], - appType: 'custom', - }); + config || {}, + ), + ); };