-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.mts
113 lines (110 loc) · 3.41 KB
/
vite.config.mts
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
import ViteYaml from '@modyfi/vite-plugin-yaml'
import vue from '@vitejs/plugin-vue'
import { readFileSync } from 'fs'
import { load } from 'js-yaml'
import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
import dynamicImport from 'vite-plugin-dynamic-import'
import { createHtmlPlugin } from 'vite-plugin-html'
import vueDevTools from 'vite-plugin-vue-devtools'
import {
vueDsfrAutoimportPreset,
vueDsfrComponentResolver
} from '@gouvminint/vue-dsfr'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
interface Config {
website: {
title: string
}
robots: {
meta: string
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const configDir = `./configs/${env.VITE_SITE_ID}`
const configFileUrl = new URL(`${configDir}/config.yaml`, import.meta.url)
const config = load(readFileSync(configFileUrl, 'utf-8')) as Config
return {
base: '/',
plugins: [
vue(),
vueDevTools(),
AutoImport({
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
imports: [
// @ts-expect-error TS2322
'vue',
// @ts-expect-error TS2322
'vue-router',
// @ts-expect-error TS2322
'vitest',
// @ts-expect-error TS2322
vueDsfrAutoimportPreset // Autoimport des composables de VueDsfr
],
vueTemplate: true,
dts: './src/auto-imports.d.ts',
eslintrc: {
enabled: true,
filepath: './eslintrc-auto-import.mjs',
globalsPropValue: true
}
}),
// Autoimport des composants utilisés dans les templates
Components({
extensions: ['vue'],
dirs: ['src/components'], // Autoimport de vos composants qui sont dans le dossier `src/components`
include: [/\.vue$/, /\.vue\?vue/],
dts: './src/components.d.ts',
resolvers: [
vueDsfrComponentResolver // Autoimport des composants de VueDsfr dans les templates
]
}),
ViteYaml(),
createHtmlPlugin({
minify: true,
inject: {
data: {
title: config.website.title,
metaRobots: config.robots.meta
}
}
}),
dynamicImport({
onFiles(files, id) {
// include only the current site routes definition in the bundle
if (id.includes('/src/router/index.ts')) {
return files.filter((routeFile) =>
routeFile.includes(`custom/${env.VITE_SITE_ID}/routes.ts`)
)
}
}
})
],
resolve: {
alias: {
'@root': resolve(__dirname, './'),
'@siteConfig': fileURLToPath(new URL(configDir, import.meta.url)),
'@': fileURLToPath(new URL('./src', import.meta.url)),
vue: 'vue/dist/vue.esm-bundler.js'
}
},
test: {
environment: 'happy-dom',
globals: true
},
server: {
// this is a dev CSP, restricting outbound requests to *.data.gouv.fr
// this makes sure we don't make unintended API calls to third-parties (looking at you iconify)
// ⚠️ this won't be applied on prod or other environments
headers: {
'Content-Security-Policy': [
"connect-src 'self' *.data.gouv.fr raw.githubusercontent.com"
].join('; ')
}
}
}
})