Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing src file silently ignored (even with nonull) #57

Closed
japgolly opened this issue Dec 27, 2013 · 5 comments
Closed

Missing src file silently ignored (even with nonull) #57

japgolly opened this issue Dec 27, 2013 · 5 comments

Comments

@japgolly
Copy link

Hello. I'm new to Grunt so I apologise if I'm doing something stupid.

I see there's been some discussion on concat ignoring missing files and I keep reading that if nonull is set to true then there is at least a warning. I've tried setting nonull to true but it's not making a difference for me. There's no indication at all that a file doesn't exist.

My Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    options: { nonull: true, },
    concat: {
      options: { nonull: true, },
      all: {
        options: { nonull: true, },
        nonull: true,
        files: {
          'all.con.js': [
            '.bower/bootstrap/dist/js/bootstrap.js',
            '.bower/jquery.ui/ui/jquery.ui.core.js',
            '.bower/jquery.ui/ui/jquery.ui.effect.js',
            '.bower/jquery.ui/ui/jquery.ui.effect-drop.js',
            'xxxxxxxxxx.js',
            'src/main/javascript/application.js',
          ],
        },
      },
    },

  });

  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.registerTask('default', ['concat']);
};

Obviously xxxxxxxxxx.js doesn't exist.

This is the output:

> grunt 
Running "concat:all" (concat) task
File "all.con.js" created.

Done, without errors.
@shama
Copy link
Member

shama commented Dec 27, 2013

nonull is a common grunt property that should neighbor the src/dest: http://gruntjs.com/configuring-tasks#files

So you were close but here is the corrected config:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      all: {
        nonull: true,
        dest: 'all.con.js',
        src: [
          '.bower/bootstrap/dist/js/bootstrap.js',
          '.bower/jquery.ui/ui/jquery.ui.core.js',
          '.bower/jquery.ui/ui/jquery.ui.effect.js',
          '.bower/jquery.ui/ui/jquery.ui.effect-drop.js',
          'xxxxxxxxxx.js',
          'src/main/javascript/application.js'
        ],
      },
    },
  });

  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.registerTask('default', ['concat']);
};

@shama shama closed this as completed Dec 27, 2013
@japgolly
Copy link
Author

Ah, that does indeed work. Thank you for the help!

@leslc
Copy link

leslc commented Sep 16, 2014

I noticed "nonull" works for the format:

    concat: {
      all: {
        nonull: true,
        dest: 'all.con.js',
        src: [
          'xxxxxxxxxx.js'
        ],
      },
    },

But not in this alternate format:

    concat: {
      all: {
        nonull: true,
        files: {
          'all.con.js' : [ 'xxxxxxxxxx.js' ]
        }
      },
    },

Is this considered a bug? Or are there other reasons why "nonull" wouldn't apply in the other format?

Thanks

@shama
Copy link
Member

shama commented Sep 16, 2014

@leslc files is used to specify multiple blocks of src/dest patterns. nonull is valid within any src/dest block. Your first example uses the regular src/dest block and thus nonull can be specified. The second uses the compact format where only a dest and src can be specified.

An example with using files is:

concat: {
  all: {
    files: [
      { src: 'xxxx.js', dest: 'all.con.js', nonull: true },
      { src: 'xxxx.js', dest: 'all2.con.js', nonull: false },
    ],
  },
},

Of course, if you're not specifying multiple src/dest blocks then files isn't necessary.

@leslc
Copy link

leslc commented Sep 16, 2014

Thank you, @shama !

I didn't know about this alternate way to specify multiple files. It works great and I prefer this syntax as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants