-
Notifications
You must be signed in to change notification settings - Fork 8
/
vite.config.js
133 lines (128 loc) · 3.58 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
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
import path from 'path';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import GitRevisionPlugin from 'git-revision-webpack-plugin';
import graphQLLoader from 'vite-plugin-graphql-loader';
import svgLoader from 'vite-svg-loader';
import svgStore from 'vite-plugin-svg-store';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import tailwindcss from 'tailwindcss';
const isProd = process.env.NODE_ENV === 'production';
// Get git information
const gitRevisionPlugin = new GitRevisionPlugin({
branch: true,
lightweightTags: true,
});
// resolve path
const resolve = dir => path.resolve(path.dirname(fileURLToPath(import.meta.url)), dir);
// asset regular expressions
const fontsRegex = /fonts\/.+\.(woff2?|eot|ttf|otf|svg)/;
const imagesRegex = /images\/.+\.(png|jpe?g|gif|webp|avif|svg|ico)/;
const mediaRegex = /media\/.+\.(mp4|webm|ogg|mp3|wav|flac|aac)/;
// https://vitejs.dev/config/
export default defineConfig(({ isSsrBuild, mode }) => {
return {
assetsInclude: [
'**/*.bin',
'**/*.wasm',
],
// Force all assets/vite calls through /static in dev mode, compiled mode is covered by the build config below
base: isProd ? '/' : '/static/',
// Use /static for all assets in prod mode
build: {
assetsDir: 'static',
assetsInlineLimit: (filePath, content) => {
const size = content.length;
if (fontsRegex.test(filePath) || mediaRegex.test(filePath)) {
return size <= 10000;
}
if (imagesRegex.test(filePath)) {
return size <= 1; // could be 10000 but we'd need to exclude apple-touch-icons
}
// vite default
return size <= 4096;
},
sourcemap: !isProd,
},
css: {
postcss: {
plugins: isProd ? [
autoprefixer,
cssnano,
tailwindcss,
] : [
tailwindcss,
],
},
preprocessorOptions: {
scss: {
// Suppress deprecation warnings from node modules
quietDeps: true,
},
},
},
define: {
UI_COMMIT: JSON.stringify(gitRevisionPlugin.commithash()),
UI_BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
UI_TAG: JSON.stringify(gitRevisionPlugin.version()),
},
plugins: [
vue({
template: {
compilerOptions: {
compatConfig: {
MODE: 3,
},
},
},
}),
// load .graphql and .gql files
graphQLLoader(),
// load svg files as vue components
svgLoader({
svgoConfig: {
plugins: [
{ name: 'removeTitle', active: false },
],
},
}),
// svg icon sprite sheet
svgStore({
dirs: ['src/assets/icons/sprite'],
symbolId: 'icon-[name]',
optimizeOptions: {
floatPrecision: 3,
},
}),
],
resolve: {
alias: {
// alias src directory
'#src': resolve('src'),
// alias kv-component directory
'#kv-components': resolve('node_modules/@kiva/kv-components/dist/components'),
// alias promise module to handle timesync calling require('promise')
promise: resolve('build/promise.js'),
// this alias is required for the rendering of src/components/Contentful/DynamicRichText.vue
// it should only be used on the client build in production
// eslint-disable-next-line max-len
...(isSsrBuild === false && mode === 'production' && { vue: path.resolve(__dirname, 'node_modules', 'vue', 'dist', 'vue.esm-bundler.js') })
},
extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
server: {
hmr: {
// Use a different client port to allow Caddy to reverse proxy with SSL cert
clientPort: 24679,
port: 24678,
},
},
optimizeDeps: {
include: [
'vue',
],
},
};
});