I am trying to use uglify with grunt to concat and minify some files. I have already used the npm to install grunt-contrib-uglify.
I have the following in my grunt.js file: (I have removed some other tasks for anonymity)
module.exports = function(grunt) {
'use strict';
grunt.loadNpmTasks('grunt-contrib-uglify');
uglify: {
options: {
sourceMap: 'app/map/source-map.js'
},
files: {
'app/dist/sourcefiles.min.js': [
'app/test_js/test.js'
]
}
}
};
I then run:
grunt uglify
but I keep getting the following error:
Warning: Maximum call stack size exceeded Use --force to continue.
If I use force, the grunt task never stops running.
Can someone tell me where I am going wrong? I am tearing my hair out on this one.
I had the same problem, using an other Grunt plugin called recess.
The error message was not explicit.
Warning: Cannot read property 'message' of undefined Use --force to continue.
But the verbose mode showed that my task was called hundred of times.
The problem was that I created a "cyclic dependency" (causing an infinite loop) when I registered my task.
grunt.registerTask('recess', ['recess']); //does not work => cyclic dependency!
The first parameter of registerTask method is an "alias task" and has to be different from the task names defined in the second parameter.
I corrected like this:
grunt.registerTask('my-recess-task', ['recess']);
And I runned the task calling this (in the Command prompt window)
grunt my-recess-task
And then it was OK!
More about registerTask() method, from grunt API:
http://gruntjs.com/api/grunt.task#grunt.task.registertask
I also met this problem, i solved this by removing
grunt.registerTask('uglify', ['uglify']);
before i solved this, i ran grunt uglify -v to check what happend.
I found it because that where you using this grunt.loadNpmTasks('grunt-contrib-uglify'); ,it implicitly executes the grunt.registerTask('uglify', ['uglify']); ^_^
Related
Here is my grunt-sass declaration.
sass: {
site: {
options: {
implementation: 'dart-sass',
style: 'compressed',
noCache: true
},
dist: {
files: {
'dist/css/jk.css' : 'src/sass/jk.scss'
}
}
}
},
When I run grunt, or grunt triggers on the watch clause, I get this output.
Running "sass:site" (sass) task
The file "dist/css/jk.css" is never created. I get no other output from Grunt. If I run sass from the command line, the file completes without any trouble.
I'm not sure why it's failing, as it's failing silently. If nothing else, I'd love to know how to enable verbose failures.
UPDATE. Tried running grunt with -v, this is the output.
Running "sass:site" (sass) task
Verifying property sass.site exists in config...OK
File: [no files]
Options: precision=10, implementation="dart-sass", style="compressed", noCache
undefined
It looks like I'm not declaring the files correctly. I'm quite certain the paths are correct. If I run sass from the command line with the same paths it succeeds as expected.
Adding -v or --verbose has returned errors. I'm still not able to compile sass, but the issue of the missing errors is resolved.
When trying to run grunt, I get an error message:
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
I have already found several posts on this topic, and in each of them the problem was a missing comma. But in my case I have no idea what's wrong, I think I didn't miss any comma (btw, this content was copy/pasted from the internet).
module.exports = (grunt) => {
grunt.initConfig({
execute: {
target: {
src: ['server.js']
}
},
watch: {
scripts: {
files: ['server.js'],
tasks: ['execute'],
},
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-execute');
};
What could be the problem?
You didn't registered the default task. Add this after the last loadNpmTask
grunt.registerTask('default', ['execute']);
The second parameter is what you want to be executed from the config, you can put there more tasks.
Or you can run run existing task by providing the name as parameter in cli.
grunt execute
With you config you can use execute and watch. See https://gruntjs.com/api/grunt.task for more information.
If you run grunt in your terminal it is going to search for a "default" task, so you have to register a task to be executed with Grunt defining it with the grunt.registerTask method, with a first parameter which is the name of your task, and a second parameter which is an array of subtasks that it will run.
In your case, the code could be something like that:
...
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-execute');
grunt.registerTask("default", ["execute", "watch"]);
...
In this way the "default" task will run rispectively the "execute" and the "watch" commands.
However here you can find the documentation to create tasks with Grunt.
Hope it was helpful.
Here's an example GruntFile for a "clean" task (using the grunt-contrib-clean plugin):
clean: {
dry: {
src: ["build/css"],
options: {
'no-write': true
}
}
}
Running grunt clean:dry would output:
Running "clean:dry" (clean) task
>> 2 paths cleaned.
Done, without errors.
Using grunt clean:dry -v, gives me what I want:
Running "clean:dry" (clean) task
Not actually cleaning live/css...
Not actually cleaning live/js...
...but it also displays a bunch of configuration logs that have nothing to do with the current task. Can I use the --verbose flag (or something else) to show the full output of a task without having to scroll through all of the non-related config logs?
PS: My other plugins suffer from the same problem, displaying only a single line of output when their documentation indicates that I should expect more.
(Related questions: Logging from grunt-contrib-jasmine and How can I force JSHint running in grunt to always use the --verbose flag do not answer this question).
There are some insights into this.
grunt.initConfig({
verbosity: {
default: {
options: { mode: 'dot' }, // normal, oneline, dot, hidden
tasks: ['groundskeeper', 'requirejs']
}
}
grunt.registerTask( '_start', ['verbosity:default', 'projectInfo'] );
I have been trying to use grunt-check-dependencies to check for NPM module dependencies before running further Grunt tasks. The problem is that this doesn't help when one of the missing NPM dependencies is a Grunt task, e.g. grunt-contrib-concat.
Since Grunt apparently registers tasks before the 'checkDependencies' task is run, even though 'checkDependencies' will successfully install any missing Grunt task modules, it does this "too late" -- Grunt has already determined that the missing modules are missing, and the Grunt build run therefore fails.
One approach that will work is to always use a command line of e.g. "npm install; grunt ...", but I thought I would see if anyone has a completely 'Grunt-internal' solution.
Here's an example Grunt output that demonstrates the issue.
% rm -rf node_modules/grunt-contrib-concat ; grunt
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
Running "checkDependencies:this" (checkDependencies) task
>> grunt-contrib-concat: not installed!
Invoking npm install...
npm http GET https://registry.npmjs.org/grunt-contrib-concat
npm http 304 https://registry.npmjs.org/grunt-contrib-concat
grunt-contrib-concat#0.3.0 node_modules/grunt-contrib-concat
Warning: Task "concat:dev" not found. Use --force to continue.
Aborted due to warnings.
Here is the example gruntfile.js that caused the above output/error:
module.exports = function(grunt) {
'use strict';
var config = {
concat: {
dev: {
src: ['foo1.js', 'foo2.js'],
dest: 'foo_concat.js'
}
},
checkDependencies: {
this: {
options: {
npmInstall: true
},
},
}
};
// trying to make sure all npm nodules listed in package.json are
// installed before other grunt tasks
grunt.loadNpmTasks('grunt-check-dependencies');
grunt.task.run('checkDependencies');
// load grunt tasks
require('load-grunt-tasks')(grunt);
// alternate approach to loading tasks; exhibits same problem
// grunt.loadNpmTasks('grunt-contrib-concat');
grunt.initConfig(config);
grunt.registerTask('default', ['concat:dev']);
}
I'm trying to get the default Yeoman Webapp to work with Assemble.io.
I followed this tutorial Using assemble.io with yeoman.io’s webapp Gruntfile
Got it up & running (partially), the first problem I have is that livereload isn't kicking in when changes are made to the .hbs files. When I manually refresh, I can see the changes that were made.
This is my Grunt file.
Second problem is that 'grunt build' gives me the following error:
Running "requirejs:dist" (requirejs) task
{ [Error: Error: Missing either an "out" or "dir" config value. If using "appDir" for a full project optimization, use "dir". If you want to optimize to one file, use "out".
at Function.build.createConfig ([MY DIRECTORY]/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:25109:19)
]
originalError: [Error: Missing either an "out" or "dir" config value. If using "appDir" for a full project optimization, use "dir". If you want to optimize to one file, use "out".] }
I googled around & when I add the following to requirejs:dist:options
appDir: '<%= yeoman.app %>/', dir: 'build'
Then this error is solved, but the next appears:
No "concat" targets found.
Warning: Task "concat" failed. Use --force to continue.
Versions:
Yeoman 1.0.4
Node 0.10.21
Bower 1.2.7
Grunt-cli 0.1.9
Grunt 0.4.1
Anyone seeing the problem? Thanks!
See this line in your gist. It's trying to call a task called concat in your Gruntfile, but that task doesn't exist. There may have been a change with the Yeoman webapp generator or you might have had a copy/paste issue or something. The assemble part of your Gruntfile looks fine.
I think you can remove the concat and carry on.