I'm using Vue 3 and Webpack 5 and wanted to install dotenv-webpack, but I can't get it to work.
Here's full code: https://github.com/golebiewska-n/webpack5-vue3
Setup: package.json
script I'm using to launch the app
webpack-cli serve
webpack.config.js
:
const Dotenv = require('dotenv-webpack')
...
module.exports = (env) => {
return {
...
plugins: [
...
new Dotenv()
]
}
}
.env
(added in the root folder of my app)
VUE_APP_VAR=123
main.js
:
console.log(process.env)
and output in console is:
MISSING_ENV_VAR
I tried removing new webpack.DefinePlugin({...})
from plugins in webpack config, but it didn't help.