- Use variable mode ------------
const common = require("./webpack.common.js")
const { merge } = require("webpack-merge")
const DotEnv = require("dotenv-webpack")
const webpack = require("webpack")
const DotenvPath = .env.${process.env.NODE_ENV}
console.log(DotenvPath) // .env.dev
module.exports = merge(common, {
plugins: [
new DotEnv({
path: DotenvPath
})
]
})

2.use string methods ------------
module.exports = merge(common, {
plugins: [
new DotEnv({
path: “.env.dev”
})
]
})
In this way, the corresponding environment file can be loaded
I'm not sure if I didn't understand the concept clearly or if dotenv-webpack is inherently flawed