-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
811279d
commit 597b0ba
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} | ||
}, | ||
}, | ||
], | ||
}); |