Issue when I run "grunt build" - gruntjs

I am working with grunt and when I write "grunt build" my dist folder builds everything, except for the js files. I get the following message:
I'm guessing I have to edit my Gruntfile, but I'm not sure how to go about solving this.
My Gruntfile is long, but here is the uglify part:

What does it mean by the destination was not written because src files were empty
It means the files listed in dist: {src:"<%config.app%>*" were not created yet. Use the following process:
Run copy and uglify manually and verbosely
grunt copy:dist --verbose
grunt uglify:dist --verbose
If it works, reorganize the task in question in the registerTask method:
grunt registerTask("build", ['copy:dist','uglify:dist']);
Otherwise, dump the <%config.app%> path to make sure it is correct
grunt.registerTask('dump', 'Dump Output', function(){ console.log(grunt.config.get() ) });
References
Grunt API: grunt.config.get
Grunt Documentation: Using the CLI

Related

Grunt Task "default" not found

I'm new to use grunt, I just create a real sample to run. But I get blocked my A warning Warning: Task "default" not found
I just copied sample from http://gruntjs.com/getting-started
My package is
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0"
}
}
my Gruntfile.js is
module.exports = function(grunt) {
grunt.registerTask('default', 'Log some stuff.', function() {
grunt.log.write('Logging some stuff...').ok();
});
};
it just print some simple log, why it doesn't work?
Copying the pasting the code from the grunt page won't do anything by itself. Did you first install grunt by console: npm install -g grunt-cli ?
Grunt is a task runner; that is, it does not have the ability to do the task itself, but starts the program listed in the gruntfile, runs the program on the noted files or folders, and stops each task before going on to the next.
You'll need to make sure that the JSHint program has been installed on your system before running grunt, or grunt won't run that task. You'll enter this in your console to install it: npm install grunt-contrib-jshint --save-dev
Grunt doesn't know what files to run JSHint on, so you'll need to tell it where to look. To do that, you'll need to carefully read the grunt-contrib-jshint page in the npm plugins site at http://gruntjs.com/plugins.
In addition, JSHint has these options: http://jshint.com/docs/options/ You'll need to learn the correct syntax to put them in the gruntfile.
Grant makes repetitive tasks simpler, but you'll still need to do a bit of homework to put all the different pieces together to get it working for you.
I wrote a complete article on getting started in grunt, based on my own learning: https://iphonedevlog.wordpress.com/2016/10/31/how-to-use-grunt-to-automate-repetitive-tasks/

How can I execute additional commands after changes detected by `compass watch`?

I've executed compass watch in a Zurb Foundation project.
It works great, my assets are compiled as I make settings changes.
However, I'd like to also run additional a few grunt commands each time I make changes.
How can I add to the actions that compass performs when changes are detected?
Specifically, I'd like to run two commands from another directory.
This is what I've got:
cd /dir_foundation/
bundle exec compasss watch
After each change, I want it to also call:
grunt sass:dist
grunt cssmin
These grunt tasks are defined in a gruntfile that is 2 directories "up" from the /dir_foundation/ where the compass watch command is monitoring changes.
I found an answer.
http://compass-style.org/help/documentation/configuration-reference/#callbacks
This is what I added to my config.rb file:
on_stylesheet_saved do |file|
system('../../../compile.bat')
end
Where "compile.bat" contains:
grunt sass:dist
grunt cssmin

Grunt Imagemin on New Files

I'm using Grunt Imagemin to optimize a folder of images. However everytime I run that command, it runs imagemin on ALL of the images. Is there a way to only run grunt imagemin when it detects new changes?
Try implementing grunt-newer:
Grunt Task for running tasks if source files are newer only.
Here you can find a short tutorial about how to use it.
After implementing it, you should prepend newer: to the imagemin task.

Using a grunt plugin's Gruntfile task rather than one from the executing Gruntfile

I have a grunt plugin, let's call it grunt-my-plugin and within the plugin's Gruntfile I have a specific cssmin task that needs to be run. Everything works as expected when testing the grunt plugin, however, when I install it on another project it gives me the following error:
Warning: Task "cssmin" not found. Use --force to continue.
At first, I was just calling grunt.task.run('cssmin'); from the plugin's task file, but then after seeing the error I realized that the Gruntfile that uses this plugin needs to be pointed to the appropriate task config, so I added:
grunt.task.loadTasks('./Gruntfile.js');
That still have me the error, so I tried:
grunt.task.loadTasks('./node_modules/grunt-my-plugin/Gruntfile.js');
Still getting the error. So, how do I fix this? The plugin does not need specific config from a Gruntfile that uses it. The cssmin task is being used to create a tmp copy and run metrics against it. Any ideas on how to achieve this? Thanks!
Ensure the following:
your plugin has the grunt-contrib-cssmin plugin listed as a dependency in package.json
you have npm install-ed in the other project (check with npm ls grunt-contrib-cssmin)
supply configuration for the cssmin task using grunt.config() before calling grunt.task.run('cssmin') (see this GitHub comment for an idea)

Is there a way to read grunt tasks via terminal?

I would like to get the registered Tasks from a gruntfile via terminal.
Example:
grunt.registerTask('test', ['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']);
then on the terminal I would type something like
$> grunt --listtasks
Even better if I could register each task with a description like so:
grunt.registerTask('test', 'this task deploys to testserver',['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']);
Then the output could be something like:
$> test: this task deploys to testserver (clean, compass, uglify, cssmin, imagemin, copy:test, ftp-deploy:test, clean)
Run grunt --help to get a list of all registered tasks. This shows the command and the task description. Example output:
$ grunt --help
Grunt: The JavaScript Task Runner (v0.4.1)
Usage
grunt [options] [task [task ...]]
Options
--help, -h Display this help text.
--base Specify an alternate base path. By default, all file paths
are relative to the Gruntfile. (grunt.file.setBase) *
--no-color Disable colored output.
--gruntfile Specify an alternate Gruntfile. By default, grunt looks in
the current or parent directories for the nearest
Gruntfile.js or Gruntfile.coffee file.
--debug, -d Enable debugging mode for tasks that support it.
--stack Print a stack trace when exiting with a warning or fatal
error.
--force, -f A way to force your way past warnings. Want a suggestion?
Don't use this option, fix your code.
--tasks Additional directory paths to scan for task and "extra"
files. (grunt.loadTasks) *
--npm Npm-installed grunt plugins to scan for task and "extra"
files. (grunt.loadNpmTasks) *
--no-write Disable writing files (dry run).
--verbose, -v Verbose mode. A lot more information output.
--version, -V Print the grunt version. Combine with --verbose for more
info.
--completion Output shell auto-completion rules. See the grunt-cli
documentation for more information.
Options marked with * have methods exposed via the grunt API and should instead
be specified inside the Gruntfile wherever possible.
Available tasks
rosetta Shared variables between JS and CSS. *
asciify Ascii awesomizer. A Grunt task for better banners and hot
logs. *
clear Clear your terminal window
clean Clean files and folders. *
concat Concatenate files. *
jshint Validate files with JSHint. *
sass Compile Sass to CSS *
watch Run predefined tasks whenever watched files change.
csso Minify CSS files with CSSO. *
lintspaces Checking spaces *
newer Run a task with only those source files that have been
modified since the last successful run.
any-newer Run a task with all source files if any have been modified
since the last successful run.
newer-timestamp Internal task.
svgmin Minify SVG *
trimtrailingspaces Removing the trailing spaces *
webfont Compile separate SVG files to webfont *
Tasks run in the order specified. Arguments may be passed to tasks that accept
them by using colons, like "lint:files". Tasks marked with * are "multi tasks"
and will iterate over all sub-targets if no argument is specified.
The list of available tasks may change based on tasks directories or grunt
plugins specified in the Gruntfile or via command-line options.
For more information, see http://gruntjs.com/
Or have a look at grunt-available-tasks:

Resources