p:: CLI
Formatting Code Automatically
- Edit
package.json > prepare
script
- Run
prepare
script once
- Add hooks:
Add the following field to the package.json
section:
Ant Design
React Router
urql
Authentication
Recoil
Env Variables and Modes
Vite exposes env variables on the special import.meta.env
object.
import.meta.env.MODE
: {string} the mode the app is running in.import.meta.env.BASE_URL
: {string} the base url the app is being served from. This is determined by the base config option.import.meta.env.PROD
: {boolean} whether the app is running in production.import.meta.env.DEV
: {boolean} whether the app is running in development (always the opposite ofimport.meta.env.PROD
)
.env Files
Vite uses dotenv to load additional environment variables from the following files in your environment directory:
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local # only loaded in specified mode, ignored by git
To prevent accidentally leaking env variables to the client, only variables prefixed with VITE_
are exposed to your Vite-processed code. e.g. the following file:
Only VITE_SOME_KEY
will be exposed as import.meta.env.VITE_SOME_KEY
to your client source code, but DB_PASSWORD
will not.