Yep there is one: __filename.
But by default webpack doesn’t leak path information and you need to set a config flag to get real filename instead of a mock ("/index.js").
// /home/project/webpack.config.js
module.exports = {
context: __dirname,
node: {
__filename: true
}
}
Than you can use __filename get the current filename relative to the context option:
// in /home/project/dir/file.js
console.log(__filename);
// => logs "dir/file.js"
The filename is only embedded into modules where __filename is used. So you don’t have to be affraid that paths are leaked from other modules.