forked from logue/vite-vue2-vuetify-ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
172 lines (170 loc) · 4.93 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { VuetifyResolver } from 'unplugin-vue-components/resolvers';
import { createVuePlugin as Vue } from 'vite-plugin-vue2';
import eslintPlugin from '@modyqyw/vite-plugin-eslint';
import Components from 'unplugin-vue-components/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, type UserConfig } from 'vite';
import stylelintPlugin from 'vite-plugin-stylelint';
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')}/`,
},
{
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: [
// Vue2
// https://github.com/underfin/vite-plugin-vue2
Vue({
target: 'esnext',
}),
// unplugin-vue-components
// https://github.com/antfu/unplugin-vue-components
Components({
// generate `components.d.ts` global declarations
dts: true,
// auto import for directives
directives: true,
// resolvers for custom components
resolvers: [
// Vuetify
VuetifyResolver(),
],
}),
// eslint
// https://github.com/ModyQyW/vite-plugin-eslint
eslintPlugin(),
// Stylelint
// https://github.com/ModyQyW/vite-plugin-stylelint
stylelintPlugin(),
// vite-plugin-checker
// https://github.com/fi3ework/vite-plugin-checker
checker({ typescript: true, vueTsc: true }),
// compress assets
// https://github.com/vbenjs/vite-plugin-compression
// viteCompression(),
],
css: {
postcss: {
plugins: [
// Fix vite build includes @charset problem
// https://github.com/vitejs/vite/issues/5655
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if (atRule.name === 'charset') {
atRule.remove();
}
},
},
},
],
},
// 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: {
manualChunks: {
// Split external library from transpiled code.
vue: [
'vue',
'vue-class-component',
'vue-property-decorator',
'vue-router',
'vue2-helpers',
'vuex',
'vuex-persist',
'deepmerge',
'@vue/composition-api',
],
vuetify: ['vuetify/lib', 'vuetify/src', 'webfontloader'],
},
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 },
},
*/
},
};
// Output build dates to Meta.ts
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;
});