-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.js
77 lines (71 loc) · 1.92 KB
/
vite.config.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { buildParserFile } from '@lezer/generator';
import path from 'path';
import fs from 'fs';
function lezer() {
const cache = {};
return {
name: 'vite-plugin-lezer',
enforce: 'pre',
resolveId(source, importer) {
if (!source.endsWith('.grammar')) {
return null;
}
return path.join(path.dirname(importer), source);
},
async load(id) {
if (!id.endsWith('.grammar')) {
return null;
}
this.addWatchFile(id);
if (!cache[id]) {
cache[id] = (async () => {
const code = await fs.promises.readFile(id, 'utf8');
return buildParserFile(code, {
fileName: id,
moduleStyle: 'es',
warn: (message) => this.warn(message),
});
})();
}
const result = await cache[id];
return result.parser;
},
watchChange(id) {
if (cache[id]) {
cache[id] = null;
}
},
};
}
const libraryBuild = {
lib: {
entry: 'src/embed.js',
name: 'MiniZincPlayground',
},
rollupOptions: {
output: {
globals: (g) => g,
},
},
};
const buildConfigs = {
library: libraryBuild,
'library-external-svelte': {
lib: {
...libraryBuild.lib,
},
rollupOptions: {
...libraryBuild.rollupOptions,
external: ['svelte', /svelte\/.*/],
},
outDir: 'dist/external-svelte',
},
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
build: buildConfigs[mode],
base: process.env.BASE_PATH,
plugins: [lezer(), svelte()],
}));