2

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')
  },
}
Josh R.
  • 276
  • 2
  • 16

1 Answers1

1

Add the ExtendedAPIPlugin

new webpack.ExtendedAPIPlugin()

__webpack_hash__ being a global, you can access everywhere.

Josh R.
  • 276
  • 2
  • 16
PlayMa256
  • 6,603
  • 2
  • 34
  • 54
  • When used in my bundled script it says: ReferenceError: __webpack_hash__ is not defined – Josh R. Dec 07 '18 at 20:27
  • Found this, https://stackoverflow.com/questions/39082976/how-to-pass-the-build-hash-as-an-environment-variable-in-webpack – Josh R. Dec 07 '18 at 21:53
  • We just need to add this plugin new webpack.ExtendedAPIPlugin() to get use of that global varaible __webpack_hash__ – Josh R. Dec 07 '18 at 21:54