Last active
October 30, 2022 13:23
-
-
Save andrejsharapov/32f2c2bc14a8d92d3edf4b14fc869cb0 to your computer and use it in GitHub Desktop.
Vite .environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV=development | |
VITE_APP_TITLE="DEV project" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV=production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
const pack = { | |
title: import.meta.env.VITE_APP_TITLE, | |
desc: import.meta.env.VITE_APP_DESCRIPTION, | |
v: import.meta.env.VITE_APP_VERSION, | |
}; | |
</script> | |
<template lang="pug"> | |
h1 {{pack.title }}@{{pack.v }} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title><%= title %>@<%= version %></title> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script type="module" src="/src/main.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { loadEnv } from "vite"; | |
import vue from "@vitejs/plugin-vue"; | |
import { createHtmlPlugin } from 'vite-plugin-html'; | |
const isDevMode = process.env.NODE_ENV !== 'production'; | |
const pkg = require('./package.json'); | |
process.env.VITE_APP_VERSION = pkg.version; | |
process.env.VITE_APP_DESCRIPTION = pkg.description; | |
if (!isDevMode) { | |
process.env.VITE_APP_TITLE = pkg.name; | |
} | |
export default ({ mode }) => { | |
const env = loadEnv(mode, process.cwd()); | |
return { | |
plugins: [ | |
vue(), | |
createHtmlPlugin({ | |
minify: true, | |
inject: { | |
data: { | |
title: env.VITE_APP_TITLE, | |
desc: env.VITE_APP_DESCRIPTION, | |
version: env.VITE_APP_VERSION, | |
} | |
} | |
}), | |
], | |
server: { | |
port: 8080, | |
}, | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment