Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to make __dirname relative #2

Open
olegstepura opened this issue Jan 26, 2017 · 1 comment
Open

Possibility to make __dirname relative #2

olegstepura opened this issue Jan 26, 2017 · 1 comment

Comments

@olegstepura
Copy link

Hi!

Is it possible to configure this plugin to make __dirname relative to some folder?
If for example I have project root and I want to inject relative file path to the resulting code it would be good to be able to write

console.log('[' + __dirname + '/' + __filename + ']', 'my stuff');

which would then expand to

console.log('[' + 'component/Main' + '/' + Main.js + ']', 'my stuff');
@SebastienGllmt
Copy link

SebastienGllmt commented Mar 7, 2020

You may be able to get away with using module.filename (global variable -- doesn't come from this library)

Example input:

console.log(module.id);

Example output:

./src/index.js

Additionally, if you're using Webpack, you can set

node: {
  __filename: true,
  __dirname: true,
},

and it will make it relative from the root directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants