webpack.config.js 437 B

1234567891011121314151617
  1. const webpack = require('webpack')
  2. const dotenv = require('dotenv')
  3. module.exports = () =>{
  4. //获取环境变量配置文件
  5. const env = dotenv.config().parsed
  6. //创建一个包含自定义环境变量的插件
  7. const envKeys =Object.keys(env).reduce((prev, next) =>{
  8. prev[`process.env.${next}`] = JSON.stringify(env[next])
  9. return prev
  10. },{})
  11. return {
  12. plugins: [
  13. new webpack.DefinePlugin(envKeys)
  14. ]
  15. }
  16. }