简体   繁体   中英

How to make Grunt search a specific directory for node modules

Grunt looks in the same folder for node_modules, but how can I tell it to look in a different folder path? I want it to look in "./js/vendor" for its modules

This seems to work as described in the issue #696 on Grunt's GitHub issue tracker.

// if you want to overload the directory on the CLI
grunt --dir=<your dir to search>

// example CLI command (relative to Gruntfile)
grunt --dir=${PWD}/js/vendor2

/**
 * Add the following code to your
 * Gruntfile.
 */

// set the custom or default directory
var customDir = grunt.option('dir') || process.cwd() + '/js/vendor';

// get the current working directory
var cwd = process.cwd();

// switch to custom directory (contains node_modules folder)
process.chdir(customDir);

// load taks(s)
grunt.loadNpmTasks('grunt-browserify2');

// switch back to original directory
process.chdir(cwd);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM