Define global variable with webpack

后端 未结 5 1734
臣服心动
臣服心动 2020-11-22 11:16

Is it possible to define a global variable with webpack to result something like this:

var myvar = {};

All of the examples I saw were using

5条回答
  •  孤城傲影
    2020-11-22 11:55

    Use DefinePlugin.

    The DefinePlugin allows you to create global constants which can be configured at compile time.

    new webpack.DefinePlugin(definitions)
    

    Example:

    plugins: [
      new webpack.DefinePlugin({
        PRODUCTION: JSON.stringify(true)
      })
      //...
    ]
    

    Usage:

    console.log(`Environment is in production: ${PRODUCTION}`);
    

提交回复
热议问题