vite-plugin-vue-env

Provide VUE_APP_ env variables to VITE app
2,916 4
Install
npm install vite-plugin-vue-env
Latest Version:1.0.6
License:MIT
Last Updated:Jan 23, 2022
Links: GitHub  ·  npm
Maintainer: notiv

Vite-plugin-vue-env

Provide VUE_APP_* env variables to Vite app.

Installation

npm i -D vite-plugin-vue-env

vite.config.ts

import { defineConfig } from 'vite';
import pluginEnv from 'vite-plugin-vue-env';

export default defineConfig({
  plugins: [
    pluginEnv(),
  ],
});

Add .env file with any VUE_APP_*

Configuration

pluginEnv(variables?, options?)

Variables

Additional variables that will be 'added' to the code, next to .env

  • type: object
  • default: {}
pluginEnv({
  APP_ENV: 'development'
})

// [in code] > console.log(process.env.APP_ENV)

Options

  • fileRegexp: Use this plugin only on files that match this regexp

    • type: RegExp
    • default: /\.(m?jsx?|tsx?|vue)$/i
    pluginEnv({}, {
      fileRegexp: /\.js$/i, // the plugin will be available only in .js files
    })
    
  • getEnvFullName: Customize replaceable string

    • type: function
    • default: (name: string) => 'process.env.${name}'
    pluginEnv({}, {
      getEnvFullName: (name: string) => `ENV.${name}`,
    })
    
    // [in code] > console.log(ENV.VUE_APP_ENDPOINT)
    
  • variablePrefix: Customize variable prefix

    • type: string
    • default: VUE_APP_
    pluginEnv({}, {
      variablePrefix: 'VUE_',
    })
    
    // [in code] > console.log(process.env.VUE_ENDPOINT)
    
  • debug: Print all variables to the console

    • type: boolean
    • default: false

How it works

Simple, maybe stupid

code.replace('process.env.var', 'value')

Related Packages

vite-plugin-nx-dotenv

Support Vite's [mode] mode of dotenv usage in Nx

5,304 1
@vitejs/plugin-vue

The official plugin for Vue SFC support in Vite.

333,357,380 686
vite-plugin-checker

Vite plugin that runs TypeScript type checker on a separate process.

133,975,562 1,242
@vitejs/plugin-vue-jsx

Provides Vue 3 JSX & TSX support with HMR.

93,663,827 686
vite-plugin-ssr

Like Next.js/Nuxt but as do-one-thing-do-it-well Vite plugin.

550,634 18

Version History

Version Released License
1.0.6 MIT
1.0.5 MIT
1.0.4 MIT
1.0.3 MIT
1.0.2 MIT