Search code examples
idesublimetext2gruntjssublimetext3

Creating a Sublime Text Grunt Build System for a specific target


I'm new to Grunt (and fairly new to sublime Text), but I've downloaded the excellent grunt build system and it works well every time I save. I'm on Win8 by the way.

The only problem is that it runs all tasks/targets. I have separated my tasks into "dist" and "dev" targets and I would like it to run only the dev tasks when I use it on save.

I'd then like to create a separate build task which I would use when building for production. Is this a sensible strategy?

Anyway, I just need to know how to modify the following build system file to just run tasks with the "dev" target....

{
  "cmd": ["grunt", "--no-color"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "working_dir": "${project_path:${folder:${file_path}}}",
  "selector": "Gruntfile.js",
  "windows":
  {
    "cmd": ["grunt.cmd", "--no-color"]
  },
  "variants":
  [
    {
      "name": "Gruntfile",
      "cmd": ["grunt", "--no-color"],
      "windows":
      {
        "cmd": ["grunt.cmd", "--no-color"]
      }
    }
  ]
}

Solution

  • You first need to create an task that runs all the dev targets:

    grunt.registerTask('dev', ['task:dev', 'task2:dev']);
    

    This can be run from the command-line using: grunt dev

    As for the Sublime build config, "cmd" is just an array of command-line arguments.

    So it would end up like this:

    {
      "cmd": ["grunt", "dev", "--no-color"],
      "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
      "working_dir": "${project_path:${folder:${file_path}}}",
      "selector": "Gruntfile.js",
      "windows":
      {
        "cmd": ["grunt.cmd", "dev", "--no-color"]
      },
      "variants":
      [
        {
          "name": "Gruntfile",
          "cmd": ["grunt", "dev", "--no-color"],
          "windows":
          {
            "cmd": ["grunt.cmd", "dev", "--no-color"]
          }
        }
      ]
    }