Passing environment-dependent variables in webpack

后端 未结 15 1920
醉酒成梦
醉酒成梦 2020-11-22 12:46

I\'m trying to convert an angular app from gulp to webpack. in gulp I use gulp-preprocess to replace some variables in the html page (e.g. database name) depending on the NO

15条回答
  •  感情败类
    2020-11-22 13:22

    You can directly use the EnvironmentPlugin available in webpack to have access to any environment variable during the transpilation.

    You just have to declare the plugin in your webpack.config.js file:

    var webpack = require('webpack');
    
    module.exports = {
        /* ... */
        plugins = [
            new webpack.EnvironmentPlugin(['NODE_ENV'])
        ]
    };
    

    Note that you must declare explicitly the name of the environment variables you want to use.

提交回复
热议问题