I am very new to task-runners in JS and this is my first attempt with GruntJS. In my Gruntfile.js I have kept several tasks like jshint
, cssmin
etc. I am able to run them all from command line, but when I run `grunt uglify' there is no response, the cursor goes to another line and remains so for hours. No error message is shown as well.
Below is my relevant code, I have tried various uglify configuration as I saw different users providing a different set of properties
//uglify:{
// options: {
// mangle : {
// except : ['jQuery', 'angular']
// },
// compress: {
// drop_console : true
// },
// banner: '*****Minified file for Pricing Plan*****',
// footer: '*********File ends**********',
// preserveComments: false
// },
// my_target:{
// options: {
// beautify: true,
// files: {
// 'scripts/pp.min.js': ['scripts/pp.js']
// }
// }
// }
//},
uglify: {
options: {
banner: '*****Minified file for Pricing Plan*****'
},
dist: {
src: 'scripts/pp.js',
dest: 'scripts/pp.min.js'
}
},
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('uglify', ['uglify']);
On command line I am running grunt uglify
Can someone suggest whats wrong here and the way to rectify it.
Just if required: Its an Angular1.x.x project
EDIT: I tried installing uglifyJs and ran the uglifyjs
command. It successfully uglifies and minifies my code. So is there any thing that needs to be done apart from what I have above.
The Issue:
I think the issue is related to how you are registering your
uglify
task. This following line of code:How to fix it:
When creating an Alias Task using
grunt.registerTask()
avoid naming thetaskName
the same as any of the items/tasks defined in thetaskList
array.NOTE: Although in the example code above I have changed the
taskName
tominify
it can be any valid name you prefer. Just ensure whatevertaskName
you choose does not also exist as one of the items in thetaskList
array.You now run the revised registered
uglify
task via CLI as follows:$ grunt minify
Gruntfile.js
Here is the revised
Gruntfile.js
:(Note: Also added forward slashes to your banner string to produce a valid JavaScript comment in the resultant file)