Gathering detailed insights and metrics for svelte-environment-variables
Gathering detailed insights and metrics for svelte-environment-variables
Gathering detailed insights and metrics for svelte-environment-variables
Gathering detailed insights and metrics for svelte-environment-variables
npm install svelte-environment-variables
Typescript
Module System
Node Version
NPM Version
62.1
Supply Chain
94.6
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
31,670
Last Day
3
Last Week
115
Last Month
391
Last Year
4,370
MIT License
2 Stars
8 Commits
1 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Feb 19, 2025
Minified
Minified + Gzipped
Latest Version
1.0.4
Package Id
svelte-environment-variables@1.0.4
Unpacked Size
6.29 kB
Size
2.91 kB
File Count
5
NPM Version
6.14.13
Node Version
14.16.0
Cumulative downloads
Total Downloads
Last Day
-85%
3
Compared to previous day
Last Week
2.7%
115
Compared to previous week
Last Month
68.5%
391
Compared to previous month
Last Year
-57.1%
4,370
Compared to previous year
No dependencies detected.
This module helps you manage environment variables in your Rollup/Webpack bundled app. The examples below use Sapper, but this is also applicable to Svelte as well as any Rollup or Webpack bundled app.
This module looks for any env variable in your process.env
with the prefix you've set (default value is SVELTE_APP_
) and replaces them in the build process in your frontend. It works great with env-cmd if you are using a .env file or you could directly make the environment variable available in the runtime of your choosing.
This module will load variables from your environment variables and check for the presence of the prefix. In case it finds the specified prefix, it will replace instances of process.env.PREFIX
in your frontend code with the actual value of the environment variable.
Steps to set this up are:
npm install svelte-environment-variables
OR
yarn add svelte-environment-variables
There are numerous ways to add environment variables to your runtime. One of the easy ways to do it is to use env-cmd. Just create a .env
file in your root directory and add a script to your package JSON to use it like so
Package.json
1{ 2 "scripts": { 3 "env:dev": "env-cmd npm run dev" 4 } 5}
With env-cmd, you can define all your environment variables in one place including the variables your SSR Node.js app might need. Only the variables with the prefix are replaced in the frontend. The rest are available on process.env
in your Node.JS app.
Additional options available with env-cmd are available here
Now we need to include this package in our bundle config file. We do it like so.
1import includeEnv from "svelte-environment-variables";
1const includeEnv = require("svelte-environment-variables");
For Rollup, we add ...includeEnv()
to the Rollup Replace plugin options.
1client: { 2 plugins: [ 3 replace({ 4 ...includeEnv(), 5 }),
For Webpack, we add ...includeEnv()
to the Webpack DefinePlugin options.
1module.exports = { 2 client: { 3 plugins: [ 4 new webpack.DefinePlugin({ 5 ...includeEnv(), 6 }),
Let's use an .env
file created at the root of your project with this content:
SVELTE_APP_ENV1="abcdxyz"
Then from any svelte component in your Sapper App:
console.log(process.env.SVELTE_APP_ENV1)
And you should see abcdxyz
in the console.
"SVELTE_APP_"
"process.env."
[]
(blank array)No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-12
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