How to pass assembly hash as environment variable in webpack?

I have an internal application that is created using webpack, which is often deployed. To facilitate error reporting, I want to include the assembly hash environment variable [hash]that webpack adds to the package names. This will allow me to quickly determine if the user is in the latest version.

Using DefinePlugin, the following does not interpolate the string and instead just stores the literal string [hash].

new webpack.DefinePlugin({
  'process.env': {
    'HASH': JSON.stringify('[hash]')
  }
})

Is there a way to access the hash directly as a variable, or is there any way to interpolate it?

+4
source share
1 answer

https://github.com/webpack/docs/wiki/list-of-plugins#extendedapiplugin

ExtendedAPIPlugin

new webpack.ExtendedAPIPlugin()

.

__webpack_hash__ var.

DefinePlugin(), __webpack_hash__, .

var hash = __webpack_hash__;
+6

Source: https://habr.com/ru/post/1652080/


All Articles