Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
147 lines (128 loc) · 4.75 KB
/
Copy pathvite.config.js
File metadata and controls
147 lines (128 loc) · 4.75 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {glob} from "glob";
import {resolve} from "path";
import eslintPlugin from "@nabla/vite-plugin-eslint";
import Icons from 'unplugin-icons/vite';
const inputs = {};
glob.sync('./frontend/js/pages/**/*.js').forEach((path) => {
// vue/pages/Admin/Index becomes AdminIndex
const entry = path.replace(/\.js$/g, '')
.replace(/^frontend\/js\/pages\//g, '')
.replace(/\//g, '');
inputs[entry] = resolve(__dirname, path)
});
// Ensure all images are included in the manifest.
glob.sync('./frontend/img/**/*.*').forEach((path) => {
const entry = path.replace(/\.[^/.]+$/g, '')
.replace(/^frontend\/img\//g, '')
.replace(/\//g, '');
inputs['img_' + entry] = resolve(__dirname, path)
});
inputs['Layout'] = resolve(__dirname, './frontend/js/layout.js');
console.log(inputs);
const frontendBaseDir = resolve(__dirname, './frontend/');
// https://vitejs.dev/config/
export default defineConfig({
root: frontendBaseDir,
base: '/static/vite_dist',
build: {
rollupOptions: {
input: inputs,
output: {
manualChunks: {
vue: ['vue'],
estoolkit: ['es-toolkit'],
leaflet: ['leaflet'],
hlsjs: ['hls.js'],
zxcvbn: ['zxcvbn'],
},
chunkFileNames: (assetInfo) => {
// Special handling for translations
if (assetInfo.name && assetInfo.name === 'translations') {
const translationParts = assetInfo.facadeModuleId
.split('/');
const translationPath = translationParts[translationParts.length - 2];
return `translations-${translationPath}-[hash:8].js`
}
// Name chunk after its file if it has one.
if (assetInfo.moduleIds.length === 1) {
const modulePath = assetInfo.moduleIds.slice().shift();
if (modulePath.includes(frontendBaseDir)) {
let path = modulePath.replace(frontendBaseDir + '/', '')
.replaceAll('/', '-');
if (path.includes('?')) {
path = path.split('?').slice(0, -1).join('?');
}
if (path.includes('.')) {
path = path.split('.').slice(0, -1).join('?');
}
return `${path}-[hash:8].js`;
}
if (modulePath.indexOf('~icons') === 0) {
const path = modulePath.split('/')
.slice(1)
.join('-');
return `icon-${path}-[hash:8].js`;
}
}
if (assetInfo.name) {
const assetName = assetInfo.name.replace(
'.vue_vue_type_style_index_0_lang',
''
).replace(
'.vue_vue_type_script_setup_true_lang',
''
);
return `${assetName}-[hash:8].js`;
}
return '[name]-[hash:8].js';
}
}
},
manifest: true,
emptyOutDir: true,
chunkSizeWarningLimit: '1m',
outDir: resolve(__dirname, './web/static/vite_dist')
},
css: {
preprocessorOptions: {
scss: {
quietDeps: true,
silenceDeprecations: ['legacy-js-api', 'import']
}
}
},
server: {
strictPort: true,
host: true,
allowedHosts: true,
fs: {
allow: [
resolve(__dirname, './frontend/'),
resolve(__dirname, './node_modules/'),
resolve(__dirname, './translations/')
]
}
},
resolve: {
alias: {
'!': resolve(__dirname, '.'),
'~': resolve(__dirname, './frontend')
},
extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
plugins: [
vue(),
Icons({
compiler: 'vue3',
iconCustomizer(collection, icon, props) {
props.class = 'icon';
props.fill = 'currentColor';
props.focusable = 'false';
props['aria-hidden'] = 'true';
},
}),
eslintPlugin(),
],
})