generated from navikt/sokos-mikrofrontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
70 lines (68 loc) · 1.84 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
import importMapPlugin from "@eik/rollup-plugin";
import terser from "@rollup/plugin-terser";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { defineConfig } from "vite";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import EnvironmentPlugin from "vite-plugin-environment";
const reactUrl = "https://www.nav.no/tms-min-side-assets/react/18/esm/index.js";
const reactDomUrl =
"https://www.nav.no/tms-min-side-assets/react-dom/18/esm/index.js";
export default defineConfig(({ mode }) => ({
base: "/attestasjon",
build: {
lib: {
entry: resolve(__dirname, "src/App.tsx"),
name: "sokos-up-attestasjon",
formats: ["es"],
fileName: () => "bundle.js",
},
},
css: {
modules: {
generateScopedName: "[name]__[local]___[hash:base64:5]",
},
},
server: {
proxy: {
...((mode === "backend" || /^.*-q1$/.test(mode)) && {
"/oppdrag-api/api/v1": {
target: /^.*-q1$/.test(mode)
? "https://sokos-oppdrag.intern.dev.nav.no"
: "http://localhost:8080",
rewrite: (path: string) => path.replace(/^\/oppdrag-api/, ""),
changeOrigin: true,
secure: /^.*-q1$/.test(mode),
},
}),
...(mode === "mock" && {
"/mockServiceWorker.js": {
target: "http://localhost:5173",
rewrite: () => "attestasjon/mockServiceWorker.js",
},
}),
},
},
plugins: [
react(),
cssInjectedByJsPlugin(),
EnvironmentPlugin({
NODE_ENV: process.env.NODE_ENV || "development",
}),
{
...importMapPlugin({
maps: [
{
imports: {
react: reactUrl,
"react-dom": reactDomUrl,
},
},
],
}),
enforce: "pre",
apply: "build",
},
terser(),
],
}));