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

@import-meta-env/babel

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@import-meta-env/babel

Load environment variables into import.meta.env object

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-5.46%
Maintainers
1
Weekly downloads
 
Created
Source

@import-meta-env/babel

CI NPM version PRs Welcome

This plugin is intended to provide a feature same as @import-meta-env/unplugin specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner or running @vue/cli@4 which needs to be transformed with babel.


This project use SemVer for versioning. For the versions available, see the tags on this repository.

Quick Start

Install and register the plugin:

$ npm i @import-meta-env/babel
// babel.config.js
module.exports = {
  plugins: [["module:@import-meta-env/babel", { example: ".env.example" }]],
};

Adjust scripts in your package.json or elsewhere:

{
  "scripts": {
    // If you have a `.env` file:
    "test": "jest",
    // If you don't have a `.env` file:
    "test": "cross-env S3_BUCKET=YOURS3BUCKET jest"
  }
}

See also:

  • examples
  • @import-meta-env/cli - A binary package is used to inject environment variables into those placeholders.
  • @import-meta-env/unplugin - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.

Plugin Options

// babel.config.js
module.exports = {
  plugins: [
    [
      "module:@import-meta-env/babel",
      /* Plugin options goes here */
      {
        env: ".env.example",
      },
    ],
  ],
};
interface PluginOptions {
  /**
   * The .env file path to load
   *
   * @default ".env"
   */
  env?: string;

  /**
   * The .env example file path to load
   */
  example: string;

  /**
   * Explicity set whether to inline current environment variables into the code,
   * instead of inject environment variables via `import-meta-env` later.
   *
   * @default
   * process.env.NODE_ENV !== 'production'
   */
  shouldInlineEnv?: boolean;
}

License

This project is licensed under the MIT License - see the LICENSE file for details

FAQs

Package last updated on 08 Mar 2022

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