Skip to content

Instantly share code, notes, and snippets.

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 faiyazalam/c7610e1a736f5aa67ceeaac1af68bfdc to your computer and use it in GitHub Desktop.
Save faiyazalam/c7610e1a736f5aa67ceeaac1af68bfdc to your computer and use it in GitHub Desktop.
access environment variable in web encore - pimcore symfony
//inside webpack config file
var Encore = require('@symfony/webpack-encore');
var dotenv = require('dotenv');
Encore
// ...
// define the environment variables
.configureDefinePlugin(options => {
const env = dotenv.config();
if (env.error) {
throw env.error;
}
options['process.env'] = JSON.stringify(env.parsed);
})
;
module.exports = Encore.getWebpackConfig();
//inside .env file
MY_ENV_VAR='MY ENV VALUE'
//inside js file
console.log(process.env.MY_ENV_VAR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment