How to get the file name of current JS File on Client

Hello, I have this use case where I need to save into a variable the current file name and use it:

/* file /client/my/container.js */

import moment from 'moment';
import '/client/my/dumb_component.js';

var fileName = getFileName(); // container.js


Any help would be appreciated.

There will be no filename available for a single component part. All js files are concatenated and minified into a single file for production.

1 Like

But I hope that at least there are some compiler-level function that could
tell me the original file where the code lives before minification. That’s
what I’am looking for

You could do some research into Javascript source maps, to see if you can make use of those.

There’s also this babel plugin which sets __dirname & __filename as variables:

1 Like