-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
116 lines (108 loc) · 2.77 KB
/
vite.config.js
File metadata and controls
116 lines (108 loc) · 2.77 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import eslint from 'vite-plugin-eslint';
import glsl from 'vite-plugin-glsl';
import path from 'path';
import typescript from '@rollup/plugin-typescript';
import examplesManifestPlugin from './vite-plugin-examples-nav.js';
// __dirname is not available in ES6 modules
// https://github.com/vitejs/vite/issues/6946#issuecomment-1041506056
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const _dirname = dirname(fileURLToPath(import.meta.url));
const MODES = ['development', 'production', 'test', 'examples'];
function modeToPlugins(mode) {
const basePlugins = [eslint(), glsl()];
const typescriptPlugin = typescript({
noForceEmit: true,
compilerOptions: {
noEmit: true,
},
});
if (mode === 'examples') {
// for examples mode, TypeScript compilation is handled by Vite's built-in esbuild
return [...basePlugins, examplesManifestPlugin()];
} else if (mode === 'development') {
return [
typescriptPlugin,
...basePlugins,
examplesManifestPlugin(),
];
} else if (!MODES.includes(mode)) {
console.error(`Unrecognized mode ${mode}`);
}
return [
typescriptPlugin,
...basePlugins,
];
}
function modeToRoot(mode) {
if (mode === 'development' || mode === 'examples') {
return 'examples';
} else if (!MODES.includes(mode)) {
console.error(`Unrecognized mode ${mode}`);
}
return undefined;
}
export default defineConfig(({ mode }) => {
const productionBuildOptions = {
sourcemap: true,
minify: 'esbuild',
copyPublicDir: false,
lib: {
entry: path.resolve(_dirname, 'src/index.ts'),
name: 'idetik-core',
fileName: "index",
},
};
return {
plugins: modeToPlugins(mode),
root: modeToRoot(mode),
publicDir: path.resolve(_dirname, 'public'),
build: {
outDir: 'dist',
target: 'es2022',
...(mode === 'production' ? productionBuildOptions : {}),
},
worker: {
format: 'es',
rollupOptions: {
output: {
format: 'es',
inlineDynamicImports: true,
},
external: [] // Bundle all dependencies for inline workers
}
},
resolve: {
alias: {
'@': path.resolve(_dirname, 'src'),
},
},
server: {
watch: {
include: [
path.resolve(_dirname, 'src/**'),
path.resolve(_dirname, 'examples/**'),
],
},
},
test: {
environment: "jsdom",
browser: {
enabled: true,
provider: "playwright",
headless: true,
instances: [
{
browser: "chromium",
},
],
},
coverage: {
provider: "istanbul",
include: ["src/**"],
},
},
}
});