Run a grunt task over a single file
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-task-file --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-task-file');
There are many tasks in grunt which run over your source files (jshint, less, ...) To run those tasks you need to provide the source files which will be affected by the tasks, and you have to do it inside grunt config. However, there are some scenarios where you would like to run the task only over a file and don't want to modify the existing grunt configuration. Grunt file comes to the rescue.
The only thing you need to do is run the file task, specifying the underlying task you want to run and the target file of the task.
Imagine you want to run jshint
task over only one file. What you have to do is only run in console:
grunt file:jshint --file some-file.js
without changing anything in Grunt configuration. This won't affect other configuration targets for the underlying task.
It is possible to set specific configuration for the underlying task, when running it over a single file. To do so,
in the config, a file
target must be specified.
grunt.initConfig({
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
all: { // Default task for all files
files: {
src: ['**/*.js']
}
},
file: { // Custom task for one file.
options: { // You can modify some options when running the task over a single file
curly: false
}
// It is not needed to specify files, as it will be done from the shell
}
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- v0.1.0 Initial version