-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
125 lines (120 loc) · 3.77 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
/// <reference types="vitest" />
import { IndexHtmlTransform, Plugin, defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import vitePluginSvgr from 'vite-plugin-svgr';
import { fileURLToPath } from 'node:url';
import { viteRequire } from 'vite-require';
const fixNavFrontendStyle = (packages: string[]) =>
packages.map((name) => ({
find: new RegExp(`${name}$`),
replacement: fileURLToPath(new URL(`node_modules/${name}/dist/main.css`, import.meta.url))
}));
const fixNavFrontendStyleNoCss = (packages: string[]) =>
packages.map((name) => ({
find: new RegExp(`${name}`),
replacement: fileURLToPath(new URL(`src/nav-style/${name}.css`, import.meta.url))
}));
const modiaFrontendCompat = (): { transformIndexHtml: IndexHtmlTransform } & Plugin => {
return {
name: 'modia-frontend-html-transform',
transformIndexHtml(html, ctx) {
if (ctx.server) {
return html.replace(/<slot environment="prod">((.|\s)*?)<\/slot>/, '');
}
return html;
}
};
};
export default defineConfig({
base: process.env.VITE_APP_BASE_PATH || '/',
server: {
port: 3000,
proxy: {
'/proxy': {
target: 'https://modiapersonoversikt.intern.dev.nav.no',
changeOrigin: true,
headers: {
Authorization: `Bearer ${process.env.LOCAL_TOKEN}`,
origin: 'modiapersonoversikt.intern.dev.nav.no'
}
},
'/modiapersonoversikt-draft': {
target: 'wss://modiapersonoversikt-draft.intern.dev.nav.no',
changeOrigin: true
}
}
},
plugins: [
react(),
vitePluginSvgr({
include: '**/*.svg'
}),
viteRequire(),
modiaFrontendCompat()
],
build: {
target: 'esnext',
outDir: 'build',
assetsDir: 'static',
sourcemap: true,
rollupOptions: {
input: {
main: 'index.html'
}
}
},
define: {
process: { env: {} }
},
resolve: {
alias: [
...fixNavFrontendStyleNoCss(['nav-frontend-etiketter-style']),
...fixNavFrontendStyle([
'nav-frontend-lenker-style',
'nav-frontend-lukknapp-style',
'nav-frontend-popover-style',
'nav-frontend-alertstriper-style',
'nav-frontend-snakkeboble-style',
'nav-frontend-modal-style',
'nav-frontend-hjelpetekst-style',
'nav-frontend-knapper-style',
'nav-frontend-spinner-style',
'nav-frontend-stegindikator-style',
'nav-frontend-typografi-style',
'nav-frontend-chevron-style',
'nav-frontend-paneler-style',
'nav-frontend-lenkepanel-style',
'nav-frontend-tabs-style',
'nav-frontend-skjema-style',
'nav-frontend-ekspanderbartpanel-style'
]),
{
find: /^~(.+)/,
replacement: '$1'
},
{
find: '~react-day-picker',
replacement: 'react-day-picker'
},
{
find: '~nav-frontend-core',
replacement: 'nav-frontend-core'
}
]
},
test: {
globals: true,
environment: 'jsdom',
environmentOptions: {
jsdom: {
url: 'http://localhost:3000'
}
},
setupFiles: './src/setupTests.ts',
css: {
modules: {
classNameStrategy: 'non-scoped'
}
}
}
});