Installations
npm install babel-plugin-replace-import-source-with-env
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
7.2.0
NPM Version
3.10.9
Score
69.8
Supply Chain
99.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
casperin
Download Statistics
Total Downloads
1,714
Last Day
1
Last Week
5
Last Month
21
Last Year
182
GitHub Statistics
1 Stars
23 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
574.00 B
Minified
370.00 B
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
1,714
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
Replace import source with env variable
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.
Install
1npm install --save-dev babel-plugin-replace-import-source-with-env
Example
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}
Options
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 theenv
variables. So in the above, the plugin will expect to be able to find aprocess.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 asprefix
.delimiters
- By default the plugin will look for{ ... }
, but it can be changed to whatever you want.
prefix and postfix insertion rules
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.
Licence
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
- Warn: no pull requests merged into dev branch
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
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