When running grunt, I get the following error:
Warning: Unable to write "client/dist/js/build.js" file (Error code: undefined). Use --force to continue.
The config of uglify in my Gruntfile.js
:
uglify: {
build: {
src: ['client/src/js/*.js'],
dest:['client/dist/js/build.js']
}
}
I'm using grunt-contrib-uglify
.
Any ideas why this is happening?
Assuming your Grunt Version is 0.4.0, AFAIK you are not using the most recent Syntax (See https://github.com/gruntjs/grunt-contrib-uglify#usage-examples).
Try
uglify: {
build: {
files: {
'client/dist/js/build.js': ['client/src/js/*.js']
}
}
}
I am also not sure if the wildcards are handled properly.
I know this is marked as solved, but I still prefer this answer from a similar question because you can easily use the files again for an other command without writing them twice.
In short, answer says
//Does not work
src: ['client/src/js/*.js'],
dest: ['client/dist/js/build.js']
//Works
src: ['client/src/js/*.js'],
dest: 'client/dist/js/build.js'
Tested working example without writing files twice:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
build: {
src: ['client/src/js/*.js'],
dest: 'client/dist/js/build.js'
}
},
watch: {
js: {
files: '<%= uglify.build.src %>',
tasks: ['uglify']
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', [
'uglify',
]);
grunt.registerTask('dev', [
'watch'
]);
};
Notice that '<%= uglify.build.src %>'
is very handy ;)
Execution
$ grunt watch
Running "watch" task
Waiting...OK
>> File "client/src/js/hello.js" changed.
Running "uglify:build" (uglify) task
File "client/dist/js/build.js" created.
Uncompressed size: 15 bytes.
Compressed size: 32 bytes gzipped (15 bytes minified).
Done, without errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With