Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions libs/vite-plugin-dot-path-fix/index.ts

This file was deleted.

34 changes: 32 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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()
})
},
}
}