API
@import-meta-env/babel
ts
export interface PluginOptions {
/**
* The .env file path to load
*
* You can out-out this by passing an empty string
*
* @default ".env"
*/
env?: string;
/**
* The public .env example file path to load
*/
example: string;
/**
* Compile-time: statically replace `import.meta.env.KEY` with `"value"`
* Runtime: statically replace `import.meta.env` with a global accessor
*
* @default
* process.env.NODE_ENV === "production" ? "runtime" : "compile-time"
*/
transformMode?: "compile-time" | "runtime";
}
@import-meta-env/cli
sh
$ npx import-meta-env --help
Usage: import-meta-env [options]
Populates your environment variables from the system or `.env` file.
Options:
-V, --version output the version number
-e, --env <path> The .env file path to load. You can out-out this by
passing an empty string. (default: ".env")
-x, --example <path> The .env example file path to load
-o, --output <path...> [deprecated: use --path] The file/dir paths to inject
in-place (default:
["dist/**/*",".next/**/*",".nuxt/**/*",".output/**/*","build/**/*"])
-p, --path <path...> The file/dir paths to inject in-place (default:
["dist/**/*",".next/**/*",".nuxt/**/*",".output/**/*","build/**/*"])
--disposable Do not create backup files and restore from backup
files. In local development, disable this option to
avoid rebuilding the project when environment
variable changes, In production, enable this option
to avoid generating unnecessary backup files.
-h, --help display help for command
@import-meta-env/flow
sh
$ npx import-meta-env-flow --help
Usage: import-meta-env-flow [options]
Generate flow type from .env.example
Options:
-V, --version output the version number
-x, --example <path> The .env example file path to load
-o, --outDir <path> Specify an output folder for emitted file. (default:
".")
-h, --help display help for command
@import-meta-env/prepare
sh
$ npx import-meta-env-prepare --help
Usage: import-meta-env-prepare [options]
Generate `.env` file from `.env.*` files.
Options:
-V, --version output the version number
-e, --env <path> .env file path to write (default: ".env")
-x, --example <path> .env.example file path to read
-p, --path <path...> .env.* file paths to read (default:
[".env.local.defaults",".env.local"])
-u, --user-environment whether to load user environment variables (i.e.,
process.env.*) (default: false)
-h, --help display help for command
@import-meta-env/swc
rs
use serde;
#[derive(serde::Serialize, serde::Deserialize)]
pub struct Config {
/**
* The .env file path to load, related to current working directory.
*
* Defaults to ".env"
*/
pub env: Option<String>,
/**
* The public .env example file path to load, related to current working directory.
*/
pub example: String,
/**
* Compile-time: statically replace `import.meta.env.KEY` with `"value"`
* Runtime: statically replace `import.meta.env` with a global accessor
*
* Default:
*
* if `TransformPluginMetadataContextKind::Env` equals to `"production"`
* then `Some(TransformMode::Runtime)`
* otherwise `Some(TransformMode::CompileTime)`
*/
#[serde(rename = "transformMode")]
pub transform_mode: Option<TransformMode>,
}
#[derive(serde::Serialize, serde::Deserialize)]
pub enum TransformMode {
#[serde(rename = "compile-time")]
CompileTime,
#[serde(rename = "runtime")]
Runtime,
}
@import-meta-env/typescript
sh
$ npx import-meta-env-typescript --help
Usage: import-meta-env-typescript [options]
Generate declaration file from .env.example
Options:
-V, --version output the version number
-x, --example <path> The .env example file path to load
-o, --outDir <path> Specify an output folder for emitted file. (default:
".")
-h, --help display help for command
@import-meta-env/unplugin
ts
export type Env = Record<string, string>;
export interface PluginOptions {
/**
* The .env file path to load
*
* You can out-out this by passing an empty string
*
* @default ".env"
*/
env?: string;
/**
* The public .env example file path to load
*/
example: string;
/**
* Compile-time: statically replace `import.meta.env.KEY` with `"value"`
* Runtime: statically replace `import.meta.env` with a global accessor
*
* @default
*
* ```text
* vite: if mode is not `"production"` then `"compile-time"`, otherwise `"runtime"`
* webpack: if mode is `"development"` or `"none"` then `"compile-time"`, otherwise `"runtime"`
* rollup: if `NODE_ENV` is not `"production"` then `"compile-time"`, otherwise `"runtime"`
* esbuild: (needs to be set explicitly)
* ```
*/
transformMode?: "compile-time" | "runtime";
}