Error when trying to use grunt-contrib-uglify: "src files were empty"
Asked Answered
F

3

7

I have the following Gruntfile.js:

module.exports = function(grunt) {
  var config = {
    pkg: grunt.file.readJSON('package.json'),
    
    /* Some other tasks... */
    
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      def: {
        files: {
          'out/src.js': 'out/src.min.js'
        }
      }
    }
  };

  grunt.initConfig(config);
  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask('default', [/* <other-tasks>, */ 'uglify:def']);
};

Folder structure is as follows:

project
  |
  +-out (folder)
  +-Gruntfile.js

Important: I run grunt from the project folder.

When running grunt, there is a task before uglify:def which is responsible for generating src.js into project/out.

When I run grunt I can see src.js being generated into project/out, but when Grunt runs uglisy:def I get the following error:

Running "uglify:def" (uglify) task.

Destination out/src.js not written because src files were empty.

No files created.

What am i doing wrong?

Log

When running with --verbose I get:

Running "uglify:def" (uglify) task
Verifying property uglify.def exists in config...OK
Files: [no src] -> out/src.js
Options: banner="/*! My Pack 2015-07-19 */\r\n", footer="", compress={"warnings":false}, mangle={}, beautify=false, report="
min", expression=false, maxLineLen=32000, ASCIIOnly=false, screwIE8=false, quoteStyle=0
>> Destination out/src.js not written because src files were empty.
>> No files created.
Fibroid answered 19/7, 2015 at 16:32 Comment(2)
Running with the verbose flag grunt <task> --verbose is helpful when diagnosing things like this. What's the output when you run the task with the verbose flag?Trondheim
Seems like it is missing the LHS of file mappings... strange.Fibroid
M
5

I've a configuration like the following, and it works fine for me.

    // uglify javascript
    uglify: {
        dev: {
            options: {
                mangle: true
            },
            files: {
                'js/dest.min.js': 'js/source.js'
            }
        }
    },

Probably you confused the destination with the source. Try to switch them.

Merce answered 19/7, 2015 at 17:1 Comment(1)
Very stupid mistake, hard to spot when you work on something for too much time. thanks man!Fibroid
A
0

It were happening due to, you are not registering above given tasks.

OK, lets start with concatenation in grunt:

concat: {
    css: {
        src: ['./assets/css/*.css', './assets/css/**/*.css'],
        dest: './dist/css/style.css'
    },
    js: {
        src: ['./assets/js/*.js', './assets/js/**/*.js'],
        dest: './dist/js/script.js'
    }
},

so, this concat is supposed to collect all css files from above given url / directories and concatenate to given destination in one place and so with js.

this will be simple concatenated style.css and script.js at dest destination directory.

but it won't work, till you not register this concat task inside below line:

grunt.registerTask('default', ['concat', 'cssmin', 'uglify']);

So, till concat will not concatenate those files in dest directory, how the uglify will collect and work!

Conclusion: task won't get execute till you not mention them inside grunt.registerTask function.

Antiphonary answered 10/11, 2018 at 3:50 Comment(0)
D
0

My problem was that the path to my source file was incorrect. So it wasn't so much that the file is "empty" but that it can't be found.

Dismantle answered 28/12, 2018 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.