-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
75 lines (71 loc) · 2.16 KB
/
vite.config.ts
File metadata and controls
75 lines (71 loc) · 2.16 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
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
export default defineConfig(({ command, mode }) => {
// Only enable dts plugin for library builds (not Storybook)
// Storybook sets mode to 'production' but doesn't define build.lib
const isLibraryBuild = command === 'build' && !process.env.STORYBOOK;
// Generate build date at build time in DD/Mon/YYYY format
const now = new Date();
const day = now.getDate();
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const buildDate = `${day}/${months[now.getMonth()]}/${now.getFullYear()}`;
// Read ENCRYPT_STORAGE from environment (default: false)
const encryptStorage = process.env.ENCRYPT_STORAGE === 'true';
return {
define: {
__BUILD_DATE__: JSON.stringify(buildDate),
__ENCRYPT_STORAGE__: JSON.stringify(encryptStorage),
},
plugins: [
// Only generate declaration files during library build, not Storybook
...(isLibraryBuild
? [
dts({
insertTypesEntry: true,
rollupTypes: true,
}),
]
: []),
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'SonarQuiz',
formats: ['iife', 'es'],
fileName: (format) => {
if (format === 'iife') return 'sonar-quiz.iife.js';
if (format === 'es') return 'sonar-quiz.esm.js';
return `sonar-quiz.${format}.js`;
},
},
rollupOptions: {
output: {
// Ensure clean global name for IIFE
name: 'SonarQuiz',
// Preserve exports for ESM
exports: 'named',
},
},
sourcemap: true,
minify: 'terser',
terserOptions: {
compress: {
drop_console: false, // Keep console for debugging
drop_debugger: true,
},
mangle: {
keep_classnames: true, // Preserve class names for custom elements
},
},
target: 'es2022',
},
optimizeDeps: {
include: ['lit'],
},
server: {
port: 3000,
open: true,
},
};
});