Gathering detailed insights and metrics for babel-plugin-replace-import-source-with-env
Gathering detailed insights and metrics for babel-plugin-replace-import-source-with-env
Gathering detailed insights and metrics for babel-plugin-replace-import-source-with-env
Gathering detailed insights and metrics for babel-plugin-replace-import-source-with-env
npm install babel-plugin-replace-import-source-with-env
Typescript
Module System
Node Version
NPM Version
69.8
Supply Chain
99.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,714
Last Day
1
Last Week
5
Last Month
21
Last Year
182
1 Stars
23 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.1
Package Id
babel-plugin-replace-import-source-with-env@1.1.1
Unpacked Size
8.99 kB
Size
2.72 kB
File Count
5
NPM Version
3.10.9
Node Version
7.2.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-16.7%
5
Compared to previous week
Last month
90.9%
21
Compared to previous month
Last year
-19.8%
182
Compared to previous year
3
Babel plugin to replace the source of an import
statement with an env
variable. This can be useful to build multiple targets/versions from one js
file.
Think one to target ios and another for android. Or a version where you
mock the api
in case you don't have, or need to work with, a real backend
(this happens all the time for me).
Wherever you find small differences that can be abstracted out into files.
1npm install --save-dev babel-plugin-replace-import-source-with-env
1// src/index.js 2import foo from "./hello{TARGET}.js";
1# Run babel with TARGET set 2TARGET=android babel src/index.js -o dist/android.js 3TARGET=ios babel src/index.js -o dist/ios.js
1// dist/andoid.js 2import foo from "./hello.android.js";
1// dist/ios.js 2import foo from "./hello.ios.js";
The plugin needs to be configured what to look for:
1// .babelrc 2{ 3 "plugins": [ 4 [ 5 "replace-import-source-with-env", 6 { 7 "identifiers": ["TARGET"] 8 } 9 ] 10 ] 11}
You can give it more options. Here are the options with their default values.
1// .babelrc 2{ 3 "plugins": [ 4 [ 5 "replace-import-source-with-env", 6 { 7 "identifiers": [], 8 "prefix": ".", 9 "postfix": "", 10 "fallback": "", 11 "delimiters": ["{", "}"] 12 } 13 ] 14 ] 15}
identifiers
are a must for this plugin to do anything. They should reflect
the env
variables. So in the above, the plugin will expect to be able to find
a process.env.TARGET
that is a string. If it doesn't it will use the
fallback.prefix
of the replaced string. It's the .
preceding the env variable.
Will not be added in case the value to be inserted is an empty string (see
below for explanation).postfix
of the replaced string. Follows same rule as prefix
.delimiters
- By default the plugin will look for { ... }
, but it can be
changed to whatever you want.Typically you want this behavior:
1// env: MOCK=mock 2import api from "./api{MOCK}" 3// to 4import api from "./api.mock" 5// ^ ^ 6// | `-- env variable 7// `---- prefix
But if MOCK
is not set, you want
1// no MOCK env 2import api from "./api{MOCK}" 3// to 4import api from "./api" 5// ^-- no env variable or prefix
To do this, we only add the prefix (and postfix) if there actually is a
non-emptly string to replace the {MOCK}
part with.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/23 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More