Using Environmental Variables
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behaviour?
Using dotenv
, expose some environmental variables with a snippet in preact.config.js
(below), additional environmental variables should be available via process.env
.
Process is undefined.
If the current behaviour is a bug, please provide the steps to reproduce.
const { plugin } = helpers.getPluginsByName(config, 'DefinePlugin')[0];
const { parsed } = require('dotenv').config();
Object.assign(
plugin.definitions,
Object.keys(parsed).reduce(
(env, key) => ({
...env,
[`process.env.${key}`]: JSON.stringify(parsed[key]),
}),
{}
)
);
package.json dependencies:
{
"devDependencies": {
"@types/dompurify": "0.0.33",
"@types/jest": "^23.3.10",
"@types/node": "^12.7.5",
"@types/prismjs": "^1.16.0",
"@types/webpack-env": "^1.13.9",
"css-loader": "^1.0.1",
"dotenv": "^8.1.0",
"husky": "^1.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.6.0",
"jest-preset-preact": "^1.0.0",
"lint-staged": "^8.1.0",
"per-env": "^1.0.2",
"preact-cli": "^3.0.0-next.19",
"prettier": "^1.15.3",
"ts-jest": "^23.10.5",
"ts-loader": "^3.5.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0",
"tslint-consistent-codestyle": "^1.14.1",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^3.6.0",
"typescript": "^3.2.1",
"typings-for-css-modules-loader": "^1.7.0",
"webpack": "^4.28.4"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.22",
"@fortawesome/free-regular-svg-icons": "^5.10.2",
"@fortawesome/free-solid-svg-icons": "^5.10.2",
"@fortawesome/react-fontawesome": "^0.1.4",
"bootstrap": "^4.3.1",
"dompurify": "^1.0.11",
"marked": "^0.7.0",
"preact": "^10.0.0-rc.1",
"preact-render-to-string": "^5.0.6",
"preact-router": "^3.0.1",
"prismjs": "^1.17.1",
"reactstrap": "^8.0.1",
"webfontloader": "^1.6.28"
}
}
What is the expected behaviour?
process.env.VARIABLE_NAME
should be available
If this is a feature request, what is motivation or use case for changing the behaviour?
Please mention other relevant information.
Please paste the results of preact info
here.
ββ
ββββββββββ
βββββββββββββββββ
βββββββββ ββββββββββ
βββββββ ββββββββ βββ
βββββ βββ βββ ββββ preact-cli 2.2.1
βββ ββββββββ βββ βββ
ββββββββββββββββββββ
ββββββββββββββββ
βββββββββ
ββ
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
An Introduction to Environment Variables and How to Use Them
An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system orΒ ...
Read more >What Are Environment Variables and How Can I Use Them ...
Environment variables are predetermined values that are typically used to provide the ability to configure a value in your code from outside ofΒ ......
Read more >Environment Variables: What They Are and How To Use Them
Environment Type: Environment variables are often used to store the name of the environment in which the app is currently running. The app'sΒ ......
Read more >Create and Modify Environment Variables on Windows
Create and Modify Environment Variables on Windows Β· On the Windows taskbar, right-click the Windows icon and select System. Β· In the Settings...
Read more >Environment variable - Wikipedia
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@UbiquitousBear I tried to reproduce the issue, but it seems like everything is working as expected.
I see that your package.json has one version, and you have another global version of
preact-cli
module. Maybe that can be the cause of your problems.I tried exposing variables from
.env
file using both3.0.0-next.19
and3.0.0-rc.5
, and everything looks fine.Iβll close this for now, given that itβs workingβ’