Alex Rock
Alex Rock

Reputation: 830

NPM: Change the `bin` output directory for the node modules

Currently, if you are using a package.json file to manage your project's dependencies (whatever project it is, may it be a ruby, php, python or js app), by default everything is installed under ./node_modules.

When some dependencies have binaries to save, they're installed under ./node_modules/.bin.

What I need is a feature that allow me to change the ./node_modules/.bin directory for ./bin.

Simple example:

A PHP/Symfony app has a ./vendor dir for Composer dependencies, and all binaries are saved in ./bin, thanks to the config: { bin-dir: bin } option in composer.json.

But if I want to use Gulp to manage my assets, I create a package.json file, require all my dependencies and then run npm install. Then, my wish is to run bin/gulp to execute gulp, but actually I have to run node_modules/.bin/gulp which is not as friendly as bin/gulp.

I've looked at package.json examples/guides on browsenpm.org and docs.npmjs.com, but none of them works, because they are here to define your own project's binaries. But I don't have any binaries, because I want to use binaries from other libraries.

Is there an option for that with NodeJS/NPM ?

Upvotes: 2

Views: 1569

Answers (1)

ChevCast
ChevCast

Reputation: 59213

You might consider adding gulp tasks to your package.json.

// package.json
{
  "scripts": {
    "build-templates": "gulp build-templates",
    "minify-js": "gulp minify-js"
  }
}

You can run any scripts specified in package.json by simply running the following:

$ npm run build-templates
$ npm run minify-js

You get the idea. You can use the gulp command inside the string without doing ./node_modules/.bin/gulp because npm is smart enough to put all scripts from ./node_modules/.bin/ into the path for that script execution.

Upvotes: 1

Related Questions