-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.js
80 lines (78 loc) · 2.44 KB
/
vite.config.js
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
import { resolve } from 'path';
import { defineConfig, splitVendorChunkPlugin as ViteVendorChunkSplit } from 'vite';
import ViteLegacy from '@vitejs/plugin-legacy';
import ViteHTMLConfig from 'vite-plugin-html-config';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
import { VitePWA } from 'vite-plugin-pwa';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import strip from '@rollup/plugin-strip';
import { visualizer } from 'rollup-plugin-visualizer';
import getTargetBrowsers from 'browserslist-to-esbuild';
import { paramCase } from 'change-case';
import { META_TAGS, PWA_CONFIG, APP_CONFIG } from './appConfig';
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
console.log(`✨ Running in ${isProd ? 'Production' : 'Development'}.\n`);
return {
resolve: {
alias: {
appConfig: resolve(__dirname, './appConfig'),
},
},
plugins: [
ViteVendorChunkSplit(),
ViteLegacy({
// inject polyfills here for modern features if needed
modernPolyfills: [],
renderLegacyChunks: false,
}),
ViteHTMLConfig({
metas: META_TAGS,
...(isProd && {
scripts: [
{
defer: true,
src: `https://static.cloudflareinsights.com/beacon.min.js?token=${APP_CONFIG.CLOUDFLARE_ANALYTICS_TOKEN}`,
},
],
}),
}),
isProd &&
ViteMinifyPlugin({
// only used to minify html files
sortAttributes: true,
removeStyleLinkTypeAttributes: true,
removeScriptTypeAttributes: true,
removeRedundantAttributes: true,
}),
VitePWA(PWA_CONFIG),
ViteImageOptimizer(),
],
preview: { open: true, port: 4000 },
server: {
open: true,
host: true,
port: 3000,
},
build: {
minify: isProd ? 'esbuild' : false,
target: getTargetBrowsers(),
sourcemap: isProd ? 'hidden' : true,
rollupOptions: {
output: {
entryFileNames: '[name].[hash].js',
chunkFileNames: file => `chunks/${paramCase(file.name)}.[hash].js`,
assetFileNames: file => `assets/${paramCase(file.name.split('.')[0])}.[hash].[ext]`,
},
plugins: [
isProd && strip(),
visualizer({
filename: 'reports/build-stats.html',
gzipSize: true,
brotliSize: true,
}),
],
},
},
};
});