Skip to content

Commit

Permalink
Bruk en plugin for å skille html mellom prod og gcp
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz committed May 14, 2024
1 parent 383f52f commit a7a2e85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<script unleash toggles="modiapersonoversikt.decorator-v3">
const applicationFeatureToggles = {
useNewDecorator: true
useNewDecorator: "$unleash{modiapersonoversikt.decorator-v3}"
};
window.applicationFeatureToggles = applicationFeatureToggles;
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"start": "vite",
"build": "vite build",
"build:gcp": "vite build --base=/",
"build:gcp": "vite build --base=/ --mode dev-gcp",
"upload-sourcemaps": "cross-env GIT_COMMIT_HASH=$(git rev-parse HEAD) node _scripts/upload-sourcemaps.js",
"test": "vitest",
"lint": "eslint --ext js,jsx,ts,tsx src",
Expand Down
30 changes: 28 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { ConfigEnv, defineConfig, Plugin } from 'vite';

import react from '@vitejs/plugin-react';
import vitePluginSvgr from 'vite-plugin-svgr';
Expand All @@ -18,6 +18,31 @@ const fixNavFrontendStyleNoCss = (packages: string[]) =>
replacement: fileURLToPath(new URL(`src/nav-style/${name}.css`, import.meta.url))
}));

const gcpEntrypoint = (): Plugin => {
let config: ConfigEnv;

return {
name: 'html-transform',
configResolved(resolvedConfig) {
config = resolvedConfig;
},
transformIndexHtml(html: string) {
if (config.mode === 'dev-gcp') {
return html.replace(
/<script unleash[\s\w\W]*?<\/script>/,
`
<script unleash toggles="modiapersonoversikt.decorator-v3">
const applicationFeatureToggles = {
useNewDecorator: true
};
window.applicationFeatureToggles = applicationFeatureToggles;
</script>`
);
}
}
};
};

export default defineConfig({
base: '/modiapersonoversikt/',
server: {
Expand All @@ -28,7 +53,8 @@ export default defineConfig({
vitePluginSvgr({
include: '**/*.svg'
}),
viteRequire()
viteRequire(),
gcpEntrypoint()
],
build: {
target: 'esnext',
Expand Down

0 comments on commit a7a2e85

Please sign in to comment.