forked from logue/vite-vuetify-ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
122 lines (118 loc) · 2.91 KB
/
vite.config.ts
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
import { type ConfigEnv, defineConfig, type UserConfig } from 'vite';
import stylelintPlugin from 'vite-plugin-stylelint';
import eslintPlugin from 'vite-plugin-eslint';
import vuetify from '@vuetify/vite-plugin';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import fs from 'fs';
// https://vitejs.dev/config/
const config: UserConfig = {
// https://vitejs.dev/config/#base
base: '/',
resolve: {
// https://vitejs.dev/config/#resolve-alias
alias: [
{
// vue @ shortcut fix
find: '@/',
replacement: `${path.resolve(__dirname, './src')}/`,
},
{
find: 'src/',
replacement: `${path.resolve(__dirname, './src')}/`,
},
],
},
// https://vitejs.dev/config/#server-options
server: {
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
},
plugins: [
// Vue3
vue(),
// Vuetify Loader
// https://github.com/vuetifyjs/vuetify-loader
vuetify({
autoImport: true,
}),
// eslint
// https://github.com/gxmari007/vite-plugin-eslint
eslintPlugin({
fix: true,
}),
// Stylelint
// https://github.com/ModyQyW/vite-plugin-stylelint
stylelintPlugin({
fix: true,
}),
// compress assets
// https://github.com/vbenjs/vite-plugin-compression
// viteCompression(),
],
css: {
// https://vitejs.dev/config/#css-preprocessoroptions
preprocessorOptions: {
sass: {
additionalData: [
// vuetify variable overrides
'@import "@/styles/variables.scss"',
'',
].join('\n'),
},
},
},
// Build Options
// https://vitejs.dev/config/#build-options
build: {
rollupOptions: {
output: {
plugins: [
/*
// if you use Code encryption by rollup-plugin-obfuscator
obfuscator({
globalOptions: {
debugProtection: true,
},
}),
*/
],
},
},
target: 'es2021',
/*
// Minify option
// https://vitejs.dev/config/#build-minify
minify: 'terser',
terserOptions: {
ecma: 2020,
parse: {},
compress: { drop_console: true },
mangle: true, // Note `mangle.properties` is `false` by default.
module: true,
output: { comments: true, beautify: false },
},
*/
},
};
// Export vite config
export default defineConfig(async (_args: ConfigEnv): Promise<UserConfig> => {
// Hook production build.
// if (_args.command === 'build') {
// Write meta data.
fs.writeFileSync(
path.resolve(path.join(__dirname, 'src/Meta.ts')),
`import type MetaInterface from '@/interfaces/MetaInterface';
// This file is auto-generated by the build system.
const meta: MetaInterface = {
version: '${require('./package.json').version}',
date: '${new Date().toISOString()}',
};
export default meta;
`
);
// }
return config;
});