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

y-dotenv

v1.0.5

Published

读取项目中 .env 文件中的变量, 注入到 process.env

Downloads

8

Readme

支持 .env 文件

读取项目中 .env 文件中的变量, 注入到 process.env

集成了 vue-cli 中的 mode 和环境变量,使用方式与之一致 即:

  1. 支持 mode
  2. 支持 local
  3. 不支持自定义路径

mode 和 local 都存在时, local 与 mode 会合并,local 优先

跟 dotenv 做同样的事, 但处理方式与 dotenv 有很大不同, dotenv 不会修改已经存在 process.env 上的变量,某些时候,

  • .env 文件里的变量跟实际代码跑的变量不一致, 属于黑盒
  • y-dotenv 始终取 .env 相关文件里的变量,属于白盒

优先级为: .env.[mode].local > .env.[mode] > .env.local > .env

example

install

# with npm
npm i y-dotenv

# or with Yarn
yarn add y-dotenv

usage

在项目根目录下创建一个 .env 文件

// .env
FOO=bar
VUE_APP_NOT_SECRET_CODE=some_value

在编译阶段,你可以使用它

const dot = require('y-dotenv')
const env = dot({ mode: "development" });
console.log(env)

| 参数 | 描述 | 例子 | | ---- | ---------------------------------------------------------------------------------------------------- | ------------------ | | mode | 需要读取的文件后缀,不传则只读.env,.env.local 文件,传递后读取 .env,.env.local,.env.[mode], .env.[mode].local 文件 | .env.development | | cwd | 查找目录,默认: process.cwd()