Created
January 27, 2023 14:50
-
-
Save faiyazalam/c7610e1a736f5aa67ceeaac1af68bfdc to your computer and use it in GitHub Desktop.
access environment variable in web encore - pimcore symfony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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
Try to avoid using dotenv. And be aware of the differences with symfony:
symfony/webpack-encore#567 (comment)