babel-plugin-transform-vite-meta-env 1.0.0
Install from the command line:
Learn more about npm packages
$ npm install @fond-of/babel-plugin-transform-vite-meta-env@1.0.0
Install via package.json:
"@fond-of/babel-plugin-transform-vite-meta-env": "1.0.0"
About this version
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.
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.PUBLIC_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.PUBLIC_VAR;
const other = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.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]) => /^PUBLIC_/.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'
};
npm install --save-dev babel-plugin-transform-vite-meta-env
{
"plugins": ["babel-plugin-transform-vite-meta-env"]
}
babel --plugins babel-plugin-transform-vite-meta-env script.js
require('@babel/core').transformSync('code', {
plugins: ['babel-plugin-transform-vite-meta-env']
})
Details
- babel-plugin-transform-vite-meta-env
- fond-of
- 7 months ago
- MIT
- 7 dependencies
Assets
- babel-plugin-transform-vite-meta-env-1.0.0.tgz
Download activity
- Total downloads 822
- Last 30 days 101
- Last week 0
- Today 0