-
Notifications
You must be signed in to change notification settings - Fork 8
/
vite.config.ts
35 lines (32 loc) · 906 Bytes
/
vite.config.ts
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
import {defineConfig, Plugin} from 'vite'
import vue from '@vitejs/plugin-vue'
import fs from "fs";
import { basename } from 'path';
import {dataToEsm} from "rollup-pluginutils";
import {dolphinFiles} from "./filesystem";
const rawSvgPlugin:Plugin = {
name: 'raw-svg-file-loader',
transform(svg: string, filepath: string) {
if (filepath.slice(-4) !== '.svg') return null;
const content = fs.readFileSync(filepath).toString()
return {
code: dataToEsm(content)
}
},
}
// Todo: How to use fs in vite?
const filesystemPlugin:Plugin = {
name: 'get-file-system-dirs',
transform(ipt: string, filepath: string) {
// shim filesystem.ts
if (basename(filepath) === 'filesystem.ts') {
return {
code: dataToEsm({dolphinFiles})
}
}
},
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), rawSvgPlugin, filesystemPlugin],
})