-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.js
105 lines (94 loc) · 3.13 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { defineConfig } from 'vite';
import { resolve } from 'path';
import handlebars from 'vite-plugin-handlebars';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
// PostCSS Plugins
import postcssPresetsEnv from 'postcss-preset-env';
const ROOT_DIR = resolve(__dirname, 'src');
const OUTPUT_DIR = resolve(__dirname, 'dist');
const BASE_PROD_URL = '/';
const BASE_DEV_URL = '/';
const BASE_API_PROD_URL = 'http://127.0.0.1:8080';
const BASE_API_TEST_URL = 'http://127.0.0.1:8080';
const BASE_API_DEV_URL = 'http://127.0.0.1:8080';
function getBaseAPIUrl(mode) {
let baseAPIUrl;
switch (mode) {
case 'production':
baseAPIUrl = BASE_API_PROD_URL;
break;
case 'test':
baseAPIUrl = BASE_API_TEST_URL;
break;
default:
baseAPIUrl = BASE_API_DEV_URL;
break;
}
console.info('ℹ️ Base API url:', baseAPIUrl);
return baseAPIUrl;
}
function getBasePublicPath(mode) {
const basePublicPath = mode === 'production' ? BASE_PROD_URL : BASE_DEV_URL;
console.info('ℹ️ Base public path:', basePublicPath);
return basePublicPath;
}
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
console.info('ℹ️ Vite command:', command);
console.info('ℹ️ Vite mode:', mode);
console.info('ℹ️ Vite isSsrBuild:', isSsrBuild);
console.info('ℹ️ Vite isPreview:', isPreview);
console.info(' ');
const basePublicPath = getBasePublicPath(mode);
return {
root: ROOT_DIR,
base: basePublicPath,
define: {
__BASE_URL__: JSON.stringify(basePublicPath),
__MODE__: JSON.stringify(mode),
__BASE_API_URL__: JSON.stringify(getBaseAPIUrl(mode)),
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
css: {
postcss: {
plugins: [
// Transpile modern CSS to support older browsers
postcssPresetsEnv({ stage: 2, autoprefixer: true }),
],
},
},
build: {
outDir: OUTPUT_DIR,
emptyOutDir: true,
rollupOptions: {
input: {
main: resolve(ROOT_DIR, 'index.html'),
thankYou: resolve(ROOT_DIR, 'thank-you', 'index.html'),
},
},
assetsDir: 'assets',
sourcemap: false,
minify: 'terser',
terserOptions: {
// Disattiva il rinominamento delle variabili/funzioni
mangle: true,
// Disattiva la compressione
compress: true,
},
cssMinify: 'lightningcss',
},
plugins: [
handlebars({
partialDirectory: resolve(ROOT_DIR, 'assets/html/partials'),
context: {
title: 'Vite Handlebars',
description: 'Vite Handlebars Starter Template',
},
}),
mode === 'production' && ViteMinifyPlugin(),
],
};
});