Skip to content

Instantly share code, notes, and snippets.

@Fanreza
Created September 30, 2022 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fanreza/aa8922450eeada82a84f747c424e17ca to your computer and use it in GitHub Desktop.
Save Fanreza/aa8922450eeada82a84f747c424e17ca to your computer and use it in GitHub Desktop.
Use .env in vite config file
import { fileURLToPath, URL } from "url";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
export default ({ mode }) => {
process.env = Object.assign(process.env, loadEnv(mode, process.cwd(), ""));
return defineConfig({
plugins: [vue()],
base: process.env.VITE_BASE_DIRECTORY, // can be used now
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment