generated from logue/vite-vue2-ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
123 lines (119 loc) · 3.32 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
123
import vue from '@vitejs/plugin-vue2';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, type UserConfig } from 'vite';
import checker from 'vite-plugin-checker';
import path from 'path';
import fs from 'fs';
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }): Promise<UserConfig> => {
const config: UserConfig = {
// https://vitejs.dev/config/#base
base: './',
// Resolver
resolve: {
// https://vitejs.dev/config/#resolve-alias
alias: [
{
// vue @ shortcut fix
find: '@/',
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: [
// Vue2
// https://github.com/vitejs/vite-plugin-vue2
vue(),
// vite-plugin-checker
// https://github.com/fi3ework/vite-plugin-checker
checker({
typescript: true,
vueTsc: true,
eslint: {
lintCommand: 'eslint', // for example, lint .ts & .tsx
},
}),
// compress assets
// https://github.com/vbenjs/vite-plugin-compression
// viteCompression(),
],
// Build Options
// https://vitejs.dev/config/#build-options
build: {
rollupOptions: {
output: {
/*
manualChunks: {
// Split external library from transpiled code.
vue: [
'vue',
'vue-class-component',
'vue-property-decorator',
'vue-router',
'vuex',
'@logue/vue2-helpers',
'@logue/vue2-helpers/vue-router',
'@logue/vue2-helpers/vuex',
],
},
*/
plugins: [
mode === 'analyze'
? // rollup-plugin-visualizer
// https://github.com/btd/rollup-plugin-visualizer
visualizer({
open: true,
filename: 'dist/stats.html',
gzipSize: true,
brotliSize: true,
})
: undefined,
/*
// if you use Code encryption by rollup-plugin-obfuscator
// https://github.com/getkey/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 },
},
*/
},
};
// 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;
});