From 597b0ba01429be8378780147bd5aab398904843f Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Sun, 17 Nov 2024 20:38:41 +0100 Subject: [PATCH] :wrench: [#724] Add vite config file An earlier prototype at least made `npm start` functional with this config, and we'd like to have the build pipeline (separate PR) use the same config as the tests. --- vite.config.mts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 vite.config.mts diff --git a/vite.config.mts b/vite.config.mts new file mode 100644 index 000000000..1e9c1e8d0 --- /dev/null +++ b/vite.config.mts @@ -0,0 +1,33 @@ +// https://vitejs.dev/config/ +import react from '@vitejs/plugin-react'; +import lodashTemplate from 'lodash/template'; +import {readFile} from 'node:fs/promises'; +import {defineConfig} from 'vite'; +import jsconfigPaths from 'vite-jsconfig-paths'; + +export default defineConfig({ + base: '/', + plugins: [ + react(), + jsconfigPaths(), + + // inspired on https://dev.to/koistya/using-ejs-with-vite-48id and + // https://github.com/difelice/ejs-loader/blob/master/index.js + { + name: 'compile-ejs', + async transform(_, id) { + const options = { + variable: 'ctx', + evaluate: /\{%([\s\S]+?)%\}/g, + interpolate: /\{\{([\s\S]+?)\}\}/g, + escape: /\{\{\{([\s\S]+?)\}\}\}/g, + }; + if (id.endsWith('.ejs')) { + const src = await readFile(id, 'utf-8'); + const code = lodashTemplate(src, options); + return `export default ${code}`; + } + }, + }, + ], +});