npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yafh/vite-plugin-env-dts

v0.3.1

Published

Auto generate env file declare for typescript of Vite plugins

Downloads

13

Readme

vite-plugin-env-dts

Auto generate env file declare for typescript of Vite plugins.

Usage

  1. Install npm i @yafh/vite-plugin-env-dts
  2. Add it into vite config file
// vite.config.ts
import envDts from '@yafh/vite-plugin-env-dts'

export default defineConfig({
  plugins: [envDts()],
})
  1. Create your env file,and start vite.

How it works

  1. When the vite service starts, the plug-in checks the envdir in the vite configuration and loads all env files.
  2. Parse all env files, extract key value pairs that conform to envprefix in the vite configuration, and generate typescript declaration files.
  3. The generated declaration file is located in node_modules/@types/env-dts/index.d.ts.

For example:

.env

VITE_FOO=foo
another=hello

.env.dev

VITE_FOO=foo
VITE_BAR=bar

# multiline comment 1
# multiline comment 2
# multiline comment 3
VITE_COMMENT=comment

VITE_COMMENT_END_OF_LINE=commentEndOfLine #end-of-line comment

.env.dev.local

VITE_FOO=foo.local
VITE_LOCAL=local

.env.prod

VITE_FOO=foo.prod

declare file

/// <reference types="vite/client" />
  
// Auto-generated by vite-plugin-env
interface ImportMetaEnv {
  /**
   * 
   * - `default` foo
   * - `dev` foo.local
   * - `prod` foo.prod
   */
  readonly VITE_FOO: string
  /**
   * 
   * - `dev` bar
   */
  readonly VITE_BAR?: string
  /**
   * # multiline comment 1
   * # multiline comment 2
   * # multiline comment 3
   * - `dev` comment
   */
  readonly VITE_COMMENT?: string
  /**
   * #end-of-line comment
   * - `dev` commentEndOfLine
   */
  readonly VITE_COMMENT_END_OF_LINE?: string
}

Options

convertValue

  • type : boolean
  • default : true

Try convert env value to boolean or number.

  1. enable convert value

env file :

# .env

VITE_FOO=bar
VITE_BOOLEAN=true
VITE_NUMBER=10
# .env.dev

VITE_FOO=2022
VITE_BOOLEAN=true
VITE_NUMBER=10

env object:

// import.meta.env
{
  VITE_FOO: 'bar', // or 2022
  VITE_BOOLEAN: true,
  VITE_NUMBER: 10,
}

declare file:

// @types/env-dts/index.d.ts

interface ImportMetaEnv {
  VITE_FOO: string | number;
  VITE_BOOLEAN: boolean;
  VITE_NUMBER: number;
}
  1. disable convert value

env file :

VITE_FOO=bar
VITE_BOOLEAN=true
VITE_NUMBER=10

env object:

// import.meta.env
{
  VITE_FOO: 'bar',
  VITE_BOOLEAN: 'true',
  VITE_NUMBER: '10',
}

declare file:

// @types/env-dts/index.d.ts

interface ImportMetaEnv {
  VITE_FOO: string;
  VITE_BOOLEAN: string;
  VITE_NUMBER: string;
}

encoding

  • type : string
  • default : 'utf8'

env file encoding

dts (0.2.2+)

  • type : string

generate declare file in custom path. (eg: typing/env.d.ts)