Josh R.
Josh R.

Reputation: 275

Using Webpack 4 can access the hash or contenthash in my javascript code, not the html?

How can I access the [name] and [contenthash] within the my code itself.

I want my loader.js file to reference the other script's file name.

webpack.config.js:

module.exports = {
  entry: {
    app: './src/index.js',
    loader: './src/loader.js'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist')
  },
}

Upvotes: 2

Views: 2579

Answers (1)

PlayMa256
PlayMa256

Reputation: 6841

Add the ExtendedAPIPlugin

new webpack.ExtendedAPIPlugin()

__webpack_hash__ being a global, you can access everywhere.

Upvotes: 1

Related Questions