diff --git a/libs/vite-plugin-dot-path-fix/index.ts b/libs/vite-plugin-dot-path-fix/index.ts deleted file mode 100644 index ee8217150d..0000000000 --- a/libs/vite-plugin-dot-path-fix/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ -import type { Plugin } from 'vite' - -/** - * Configure a safelist of path patterns that can be redirected to `/` despite - * having a dot in them. - * - * Vite does not rewrite paths with dots in them to serve `/index.html`, likely - * because it wants to assume they are static files that should be served - * directly. See https://github.com/vitejs/vite/issues/2415. - * - * We have a few non-file console paths that we expect to contain a dot. Names - * cannot contain dots, but semver versions always will. So we safelist some - * paths that we expect to have dots so they will work in the dev server. - * - * If a path needs to be added to this safelist, it will show up as a blank page - * in local dev and the Vite `--debug` output will say: - * - * "Not rewriting GET /has.dot because the path includes a dot (.) character." - */ -export const dotPathFixPlugin = (safeDotPaths: RegExp[]): Plugin => ({ - name: 'dot-path-fix', - configureServer: (server) => { - server.middlewares.use((req, _, next) => { - if (req.url && safeDotPaths.some((p) => req.url?.match(p))) { - req.url = '/' - } - next() - }) - }, -}) diff --git a/vite.config.ts b/vite.config.ts index ddaa1f76da..7ba6e343a3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,11 +8,10 @@ import { resolve } from 'path' import basicSsl from '@vitejs/plugin-basic-ssl' import react from '@vitejs/plugin-react-swc' -import { defineConfig } from 'vite' +import { defineConfig, type Plugin } from 'vite' import { createHtmlPlugin } from 'vite-plugin-html' import { z } from 'zod' -import { dotPathFixPlugin } from './libs/vite-plugin-dot-path-fix' import tsConfig from './tsconfig.json' const ApiMode = z.enum(['msw', 'dogfood', 'nexus']) @@ -149,3 +148,34 @@ export default defineConfig(({ mode }) => ({ includeSource: ['app/**/*.ts', 'libs/**/*.ts'], }, })) + +/** + * Configure a safelist of path patterns that can be redirected to `/` despite + * having a dot in them. + * + * Vite does not rewrite paths with dots in them to serve `/index.html`, likely + * because it wants to assume they are static files that should be served + * directly. See https://github.com/vitejs/vite/issues/2415. + * + * We have a few non-file console paths that we expect to contain a dot. Names + * cannot contain dots, but semver versions always will. So we safelist some + * paths that we expect to have dots so they will work in the dev server. + * + * If a path needs to be added to this safelist, it will show up as a blank page + * in local dev and the Vite `--debug` output will say: + * + * "Not rewriting GET /has.dot because the path includes a dot (.) character." + */ +function dotPathFixPlugin(safeDotPaths: RegExp[]): Plugin { + return { + name: 'dot-path-fix', + configureServer: (server) => { + server.middlewares.use((req, _, next) => { + if (req.url && safeDotPaths.some((p) => req.url?.match(p))) { + req.url = '/' + } + next() + }) + }, + } +}