-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
69 lines (65 loc) · 1.61 KB
/
Copy pathvite.config.js
File metadata and controls
69 lines (65 loc) · 1.61 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { readFileSync } from 'fs';
import { minifyHTMLLiterals } from 'minify-literals';
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
const banner = `/**
* @license MIT
* @name ${pkg.name}
* @version ${pkg.version}
* @author Softwarity (https://www.softwarity.io/)
* @copyright ${new Date().getFullYear()} Softwarity
* @see https://github.com/softwarity/interactive-code
*/`;
// Custom Vite plugin to minify template literals (CSS/HTML)
function minifyLiteralsPlugin() {
return {
name: 'minify-literals',
async transform(code, id) {
if ((id.endsWith('.js') || id.endsWith('.ts')) && code.includes('`')) {
try {
const result = await minifyHTMLLiterals(code, { fileName: id });
return result ? { code: result.code, map: result.map } : null;
} catch (e) {
return null;
}
}
return null;
}
};
}
export default defineConfig({
plugins: [minifyLiteralsPlugin()],
define: {
__VERSION__: JSON.stringify(pkg.version)
},
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'InteractiveCode',
fileName: 'interactive-code',
formats: ['es']
},
minify: 'terser',
terserOptions: {
compress: {
passes: 3
},
mangle: {
toplevel: true
},
format: {
comments: false,
preamble: banner
}
},
rollupOptions: {
output: {
assetFileNames: 'interactive-code.[ext]'
}
}
},
server: {
open: '/demo/index.html'
}
});