Skip to content

Commit

Permalink
🔧 [#724] Add vite config file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Nov 26, 2024
1 parent 811279d commit 597b0ba
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -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}`;
}
},
},
],
});

0 comments on commit 597b0ba

Please sign in to comment.