admin管理员组

文章数量:1387304

The code

My latest mit is in a repo on GitHub.

The problem...

I am setting up a project (link above) using GruntJS. While trying to run any Grunt task, I'm getting a No "<insert-taskname>" targets found; a few examples:

  1. No "browserSync" targets found. Warning: Task "browserSync" failed. Use --force to continue.

  2. No "jshint" targets found. Warning: Task "jshint" failed. Use --force to continue.

  3. No "sass" targets found. Warning: Task "sass" failed. Use --force to continue.

What I'm doing

I am using external .js Grunt config files using the load-grunt-configs plugin. I have used a very similar setup in other projects without problems. I'm passing the shared Grunt variables which were initialized in the Gruntfile.js to each of the grunt-configs files using the options object that is a part of the load-grunt-configs plugin.

What I've tried so far...

I've tried checking my Grunt variables that are being used in the external config files, double checking my syntax and bracket matching, and searching through other stack overflow questions with no luck.

Any help would be greatly appreciated! Thank you.

The code

My latest mit is in a repo on GitHub.

The problem...

I am setting up a project (link above) using GruntJS. While trying to run any Grunt task, I'm getting a No "<insert-taskname>" targets found; a few examples:

  1. No "browserSync" targets found. Warning: Task "browserSync" failed. Use --force to continue.

  2. No "jshint" targets found. Warning: Task "jshint" failed. Use --force to continue.

  3. No "sass" targets found. Warning: Task "sass" failed. Use --force to continue.

What I'm doing

I am using external .js Grunt config files using the load-grunt-configs plugin. I have used a very similar setup in other projects without problems. I'm passing the shared Grunt variables which were initialized in the Gruntfile.js to each of the grunt-configs files using the options object that is a part of the load-grunt-configs plugin.

What I've tried so far...

I've tried checking my Grunt variables that are being used in the external config files, double checking my syntax and bracket matching, and searching through other stack overflow questions with no luck.

Any help would be greatly appreciated! Thank you.

Share Improve this question edited Apr 19, 2016 at 14:19 qbeauperin 5895 silver badges21 bronze badges asked Aug 16, 2014 at 18:58 user3773571user3773571
Add a ment  | 

2 Answers 2

Reset to default 4

I remend using the idiomatic and built-in methods of breaking up your Gruntfile instead. 3rd party solutions tend to stray far from the Grunt APIs.

Create a folder named tasks/ and within that folder add files similar to what you're currently doing now.

Load all of those files in your main Gruntfile using grunt.loadTasks():

// Gruntfile.js
module.exports = function(grunt) {
  // Initialize config.
  grunt.initConfig({
    pkg: require('./package.json'),
  });

  // Load per-task config from separate files.
  grunt.loadTasks('tasks');
};

Each of those files are formatted like mini Gruntfiles. Here is an example for jshint:

// tasks/jshint.js
module.exports = function(grunt) {
  grunt.config('jshint', {
    app: {
      options: {jshintrc: 'app/.jshintrc'},
      src: ['app/**/*.js'],
    },
  });
  grunt.loadNpmTasks('grunt-contrib-jshint');
};

Here is a full example of this solution from the creator of Grunt himself: https://github./cowboy/wesbos

your problem is inside your config tasks.

you are doing

module.exports = {

you need to do:

module.exports.tasks = {

other than that i remend following kyle's answer, as it is much cleaner to use grunt's built in features!

本文标签: javascriptGruntJS setup No targets foundStack Overflow