Skip to content

Instantly share code, notes, and snippets.

@josfaber
Created January 30, 2022 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josfaber/d937ca0791bd359f43a2861cded6807a to your computer and use it in GitHub Desktop.
Save josfaber/d937ca0791bd359f43a2861cded6807a to your computer and use it in GitHub Desktop.
load .env in webpack config
require('dotenv').config({ path: path.resolve( __dirname, '../../.env' ) });
module.exports = {
...
plugins: [
new HtmlWebpackPlugin( { template: './src/index.html' } ),
new webpack.DefinePlugin( {
"process.env": JSON.stringify(process.env)
} ),
],
...
};
/**
Now in html file use <%= process.env.GTAG_ID %>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment