Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
83 lines (81 loc) · 2.01 KB
/
Copy pathvite.config.js
File metadata and controls
83 lines (81 loc) · 2.01 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
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
import { readFileSync } from 'fs';
const pkg = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
export default defineConfig({
define: {
__PKG_VERSION__: JSON.stringify(pkg.version),
},
plugins: [
dts({
include: ['src/**/*.ts', 'src/**/*.tsx'],
exclude: ['src/**/*.test.ts', 'src/**/*.test.tsx'],
rollupTypes: true,
insertTypesEntry: true,
}),
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'HygraphPreviewSDK',
formats: ['es', 'cjs', 'umd'],
fileName: (format) => {
switch (format) {
case 'es':
return 'index.esm.js';
case 'cjs':
return 'index.cjs.js';
case 'umd':
return 'index.umd.js';
default:
return `index.${format}.js`;
}
},
},
outDir: 'dist',
rollupOptions: {
external: (id) => {
// Externalize React and its JSX runtime
return id === 'react' ||
id === 'react-dom' ||
id === 'react/jsx-runtime' ||
id === 'react/jsx-dev-runtime' ||
id.startsWith('react/');
},
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'React',
'react/jsx-dev-runtime': 'React',
},
exports: 'named',
},
},
sourcemap: true,
minify: 'terser',
terserOptions: {
compress: {
drop_console: false,
drop_debugger: true,
},
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
test: {
include: [
'src/**/*.test.{ts,tsx}',
'src/**/*.spec.{ts,tsx}',
'tests/**/*.test.{ts,tsx}',
'tests/**/*.spec.{ts,tsx}',
],
exclude: ['node_modules/**', 'dist/**', 'examples/**'],
environment: 'jsdom',
passWithNoTests: true,
},
});