vite env variables replaced twice with vite command

71 Views Asked by At

I have the index.html with following static script. Since vite doesnt build static file, I added the env variable.

<script src="%VITE_BASE_URL%test.js"></script>

The build command replaces the env variable properly, But for the serve command i.e vite it seems to prefix twice the base url. The vite config and base url

VITE_BASE_URL = /testurl/

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
   base: env.VITE_BASE_URL,
   server: {
     port: 8080
   }
  }
});

So the test.js url turns to

localhost:8080/testurl/testurl/test.js

Can someone let me know what the reason could be.

Vite version is 4.5.0

0

There are 0 best solutions below