How to resolve the path inside the grunt plugin task to its own resources?

I have a grunt plugin sample

/tasks sample.js config.file Gruntfile.js package.json 

I want to get the path to config.file inside sample.js. At first I did it like this:

 path.resolve('tasks/config.file') 

Everything was fine until the plugin was installed. The path to config.file has been changed to '~ / some_project / node_modules / sample_plugin / tasks / config.file', but path.resolve returned '~ / some_project / tasks / config.file'.

How can I get the correct path to config.file?

+4
source share
1 answer

It turned out that I asked the question in the wrong direction. My question belonged to nodejs not to gruntjs. The answer is the __ dirname directive. You can get the full path to config.file as follows: __dirname + path.sep + 'config.file'

+4
source

All Articles