Socket
Socket
Sign inDemoInstall

vite-register

Package Overview
Dependencies
2
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vite-register

Require hook allowing to use Vite env variables inside Node scripts and tests runners.


Version published
Weekly downloads
5
decreased by-76.19%
Maintainers
1
Install size
31.5 kB
Created
Weekly downloads
 

Readme

Source

vite-register

version CI downloads install size

Require hook allowing to use Vite env variables inside Node scripts and tests runners.


Install

npm install --save-dev vite-register

Features

Pretty much like Vite does, vite-register will statically replace variables.

  • Support import.meta.env.MODE (based on process.env.NODE_ENV, defaults to development)
  • Support import.meta.env.DEV
  • Support import.meta.env.PROD
  • Support experimental import.meta.env.SSR (defaults to false)
  • Support import.meta.env.BASE_URL (defaults to /)
  • Support loading variables prefixed with VITE_
    • from a .env file
    • from a .env.local file
    • from a .env.[mode] file
    • from a .env.[mode].local file

Usage

This hook can be used with the Node CLI and in some test runners supporting hooks via the -r (--require) option.

echo 'VITE_FOO="hello world"' > .env
echo 'console.log(import.meta.env.VITE_FOO);' > index.js
node -r vite-register index.js
> hello world

vite-register can look into Vite configuration files (vite.config.[ext]) and retrieve base.

Add some hook like tsm or esbuild-runner before using vite-register, when needing to support TypeScript/ESM support in scripts and configuration files.

node -r esbuild-runner/register -r vite-register index.ts

Mocha

↪️ mochajs/mocha

Can be combined with esbuild-runner for TypeScript/ESM support.

mocha -r esbuild-runner/register -r vite-register [pattern]

uvu

↪️ lukeed/uvu

Can be combined with tsm or esbuild-runner for TypeScript/ESM support.

uvu -r tsm -r vite-register [pattern]

License

MIT

Keywords

FAQs

Last updated on 29 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc