3

Trying to load module: grunt.loadNpmTasks('grunt-express-server'); from an external directory.

Get an error: task .... does not exist. Have you loaded it?

Directory structure:

client/
  node_modules
  gruntfile
dev_server/
  node_modules/
    grunt-express-server

So my question is: how do you run a grunt-task using a node-module which is stored in a external directory?

SSchmidt
  • 78
  • 5
raneshu
  • 363
  • 2
  • 16
  • 46

1 Answers1

6

You will need to use grunt.task.loadtasks pointing it to the task directory which you want to load the tasks.

In your case:

grunt.loadTasks('../dev_server/node_modules/grunt-express-server/tasks');

If you check grunt's master on github, at line 325 of task.js it requires the taskfile (.../tasks/express.js) located in the filepath you passed as parameter.

// Load taskfile.
fn = require(path.resolve(filepath))

Edit

If you're wondering if you can relocate the grunt's path to node_modules, check out this question

Community
  • 1
  • 1
jmartins
  • 991
  • 4
  • 16