Dotenv: How to use with webpack?

Created on 23 Oct 2019  路  3Comments  路  Source: motdotla/dotenv

Hello.

I have a very basic webpack setup with just typescript + react support. For now, I have

.env
app.tsx
webpack.config.js

The .env just contains GITHUB_URL=https://github.com/samayo
app.tsx is just a simple react "hello world" which outputs process.env.GITHUB_URL via console.log
webpack.config.js contains the require('dotenv').config() code

but, somehow the variable is null. Am I missing some configuration?

All 3 comments

You'll likely want to use webpack's DefinePlugin instead of dotenv

Please add that in the readme so you can save another person from frustration. That should've been mentioned in the first place.

@samayo I know it's late but there's https://www.npmjs.com/package/dotenv-webpack that works smoothly with webpack. You can play with the configuration to enable features and it's pretty simple to use.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goldbergyoni picture goldbergyoni  路  3Comments

Vandivier picture Vandivier  路  3Comments

danawoodman picture danawoodman  路  3Comments

AndrewChen1982 picture AndrewChen1982  路  4Comments

mattcdavis1 picture mattcdavis1  路  5Comments