Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@import-meta-env/unplugin
Advanced tools
This plugin helps us inject environment variables into the import.meta.env
object after building the application instead of statically replacing it during production.
This project use SemVer for versioning. For the versions available, see the tags on this repository.
Environment variables should be easy to change between deployments without rebuilding the application or even changing any code, so we should set environment variables on the system instead of checking them into a repository with .env
files.
During production, this plugin generates chunks with placeholders, which allow us to statically replace environment variables after building the application (don't worry, we provide an executable for this, you don't need to write them yourself) .
Install and register the plugin:
$ npm i dotenv @import-meta-env/unplugin @import-meta-env/cli
// vite.config.ts
import ImportMetaEnvPlugin from "./@import-meta-env/unplugin";
export default {
plugins: [
ImportMetaEnvPlugin.vite({
/* options */
}),
],
};
// rollup.config.js
import ImportMetaEnvPlugin from "./@import-meta-env/unplugin";
export default {
plugins: [
ImportMetaEnvPlugin.rollup({
/* options */
}),
],
};
// webpack.config.js
module.exports = {
plugins: [
require("./@import-meta-env/unplugin").webpack({
/* options */
}),
],
};
// esbuild.config.js
import { build } from "esbuild";
build({
plugins: [
require("./@import-meta-env/unplugin").esbuild({
/* options */
}),
],
});
Create a .env.example
file in the root of your project:
# .env.example
# To prevent exposure of sensitive credentials to clients,
# only the keys defined in this file can be accessed.
S3_BUCKET=
Add .env
file to .gitignore, and create a .env
file in the project's root directory:
(⚠ This step is completely optional, you should set environment variables directly on your system if you can.)
# .env
S3_BUCKET="YOURS3BUCKET"
SECRET_KEY="YOURSECRETKEYGOESHERE"
import.meta.env
now has the keys and values you defined on your system:
console.log(import.meta.env.S3_BUCKET); // "YOURS3BUCKET"
console.log(import.meta.env["S3_BUCKET"]); // "YOURS3BUCKET", dynamic key also works
console.log(import.meta.env.SECRET_KEY); // undefined
Finally, before serving your application, remember to execute import-meta-env
binary to inject environment variables, for example:
$ cross-env S3_BUCKET=YOURS3BUCKET import-meta-env && your-serve-script
See also:
Please see types.ts
This project is licensed under the MIT License - see the LICENSE file for details
FAQs
Build once, deploy anywhere. Startup/runtime environment variable solution for JavaScript.
We found that @import-meta-env/unplugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.