From c2014f73f6dd0f688b9b61cf39ce11f9b0556a21 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Sun, 24 Apr 2022 19:28:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Suppression=20du=20hack=20sur=20?= =?UTF-8?q?la=20config=20vitejs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Faux point d'entrée qui menait vers un fichier vide --- site/package.json | 1 - site/prerender.cjs | 1 + site/source/entry-empty.js | 3 --- site/vite.config.ts | 15 +++++++-------- 4 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 site/source/entry-empty.js diff --git a/site/package.json b/site/package.json index 8dc43f6ee..110d1cff0 100644 --- a/site/package.json +++ b/site/package.json @@ -9,7 +9,6 @@ "directory": "site" }, "private": true, - "main": "./source/entry-empty.js", "engines": { "node": ">=12.16.1" }, diff --git a/site/prerender.cjs b/site/prerender.cjs index ad39be361..9a752e41f 100644 --- a/site/prerender.cjs +++ b/site/prerender.cjs @@ -3,6 +3,7 @@ // CommonJS when I wrote it. // cf. https://github.com/vitejs/vite/blob/133fcea5223263b0ae08ac9a0422b55183ebd266/packages/vite/src/node/build.ts#L495 // cf. https://github.com/vitejs/vite/pull/2157 +// cf. https://github.com/vitejs/vite/pull/6812 // TODO: We could use something like https://github.com/Aslemammad/tinypool to // prerender all pages in parallel (used by vitest). Or move to SSR with a diff --git a/site/source/entry-empty.js b/site/source/entry-empty.js deleted file mode 100644 index 5409001a3..000000000 --- a/site/source/entry-empty.js +++ /dev/null @@ -1,3 +0,0 @@ -// TODO: for some reason (ViteJS bug or missconfiguration on our side?) we need -// to define a entry file in the "main" field of package.json. We should remove -// this empty file when this problem is fixed. diff --git a/site/vite.config.ts b/site/vite.config.ts index b3c2d14f5..98fa5c1d8 100644 --- a/site/vite.config.ts +++ b/site/vite.config.ts @@ -157,20 +157,19 @@ function multipleSPA(options: MultipleSPAOptions): Plugin { // eslint-disable-next-line @typescript-eslint/no-misused-promises vite.middlewares.use(async (req, res, next) => { const url = req.originalUrl + const firstLevelDir = url?.slice(1).split('/')[0] + if (url === '/') { res.writeHead(302, { Location: '/' + options.defaultSite }) res.end() } else if ( - url && - Object.keys(options.sites).some((name) => - url.slice(1).startsWith(name) - ) + firstLevelDir && + Object.keys(options.sites).some((name) => firstLevelDir === name) ) { - const siteName = url.slice(1).split('/')[0] + const siteName = firstLevelDir const content = await vite.transformIndexHtml( - '/', - await fillTemplate(siteName), - url + url, + await fillTemplate(siteName) ) res.end(content) } else {