Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0kzh/babel-plugin-transform-vite-meta-env

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0kzh/babel-plugin-transform-vite-meta-env

babel plugin that emulates vite's import.meta.env functionality

  • 0.0.0-semantically-released
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-vite-meta-env

Build Status codecov version downloads MIT License

PRs Welcome Code of Conduct Discord

Watch on GitHub Star on GitHub Tweet

Please note: this plugin is intended to provide an approximation of some of Vite specific transformations when running the code in non-Vite environment, for example, running tests with a NodeJS based test runner.

The functionality within these transformations should not be relied upon in production.

Example

In

const mode = import.meta.env.MODE;
const baseUrl = import.meta.env.BASE_URL;
const nodeEnv = import.meta.env.NODE_ENV;
const dev = import.meta.env.DEV;
const prod = import.meta.env.PROD;
const viteVar = import.meta.env.VITE_VAR;
const other = import.meta.env.OTHER;
const env = import.meta.env;

Out

const mode = process.env.MODE;
const baseUrl = '/';
const nodeEnv = process.env.NODE_ENV || 'test';
const dev = process.env.NODE_ENV !== 'production';
const prod = process.env.NODE_ENV === 'production';
const viteVar = process.env.VITE_VAR;
const other = {
  ...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
  NODE_ENV: process.env.NODE_ENV || 'test',
  MODE: process.env.NODE_ENV || 'test',
  BASE_URL: '/',
  DEV: process.env.NODE_ENV !== 'production',
  PROD: process.env.NODE_ENV === 'production'
}.OTHER;
const env = {
  ...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
  NODE_ENV: process.env.NODE_ENV || 'test',
  MODE: process.env.NODE_ENV || 'test',
  BASE_URL: '/',
  DEV: process.env.NODE_ENV !== 'production',
  PROD: process.env.NODE_ENV === 'production'
};

Installation

npm install --save-dev babel-plugin-transform-vite-meta-env

Usage

{
  "plugins": ["babel-plugin-transform-vite-meta-env"]
}

Via CLI

babel --plugins babel-plugin-transform-vite-meta-env script.js

Via Node API

require('@babel/core').transformSync('code', {
  plugins: ['babel-plugin-transform-vite-meta-env']
})

Keywords

FAQs

Package last updated on 17 Jan 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc