-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
64 lines (62 loc) · 1.77 KB
/
vite.config.js
File metadata and controls
64 lines (62 loc) · 1.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
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import fs from 'fs';
import { defineConfig, loadEnv } from 'vite';
import eslint from 'vite-plugin-eslint';
import legacy from '@vitejs/plugin-legacy';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const isDevHTTPSEnabled =
typeof env.HTTPS_CERT === 'string' && typeof env.HTTPS_KEY === 'string';
return {
server: isDevHTTPSEnabled
? {
https: {
key: fs.readFileSync(env.HTTPS_KEY),
cert: fs.readFileSync(env.HTTPS_CERT),
},
}
: undefined,
plugins: [
eslint(),
legacy({
targets: ['defaults', 'not IE 11'],
}),
{
name: 'csp',
transformIndexHtml(html) {
const csp = `default-src 'none'; script-src 'self'; connect-src 'self' https://api.github.com; img-src 'self'; style-src 'self'; form-action 'self'; object-src 'none'; media-src 'self'; base-uri 'none'; upgrade-insecure-requests;`;
html = html.replace(
/<head>/,
`<head>\n<meta http-equiv="Content-Security-Policy" content="${csp}">`
);
return html;
},
},
],
build: {
outDir: 'dist/browser',
rollupOptions: {
output: {
entryFileNames: '[name].[hash].js',
chunkFileNames: '[name].[hash].js',
assetFileNames: '[name].[hash].[ext]',
},
},
sourcemap: false,
minify: 'terser',
terserOptions: {
format: {
comments: false,
},
parse: {
html5_comments: false,
},
sourceMap: false,
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
};
});