-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
36 lines (32 loc) · 911 Bytes
/
Copy pathvite.config.ts
File metadata and controls
36 lines (32 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Multi-page dev + build: routes and Rollup inputs come from `multi-page.ts`.
* Production pretty URLs: keep `netlify.toml` in sync (guarded by tests).
*/
import type { Connect, Plugin } from 'vite';
import { defineConfig } from 'vite';
import { devPrettyRoutes, rollupHtmlInputs } from './multi-page';
const shortHtmlRoutes: Connect.NextHandleFunction = (req, _res, next) => {
if (!req.url) {
next();
return;
}
const hit = devPrettyRoutes.find((r) => req.url === r.path || req.url === `${r.path}/`);
if (hit) req.url = hit.html;
next();
};
function shortHtmlRoutesPlugin(): Plugin {
return {
name: 'gatekeeper-short-html-routes',
configureServer(server) {
server.middlewares.use(shortHtmlRoutes);
},
};
}
export default defineConfig({
plugins: [shortHtmlRoutesPlugin()],
build: {
rollupOptions: {
input: { ...rollupHtmlInputs },
},
},
});