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

Not working with grunt-contrib-imagemin #9

Closed
evanmcd opened this issue Sep 20, 2013 · 7 comments
Closed

Not working with grunt-contrib-imagemin #9

evanmcd opened this issue Sep 20, 2013 · 7 comments

Comments

@evanmcd
Copy link

evanmcd commented Sep 20, 2013

Given that it works with other contrib plugins, like copy and uglify, it would be great if it worked with imagemin.

Here's my imagemin config:

    imagemin: {
        main: {
        files: [{
          expand: true,
          cwd: 'Source/',
          src: ['**/*.{png,jpg,gif}'],
          dest: 'Runtime/'
        }]
      }
    },

and my registerTask:

grunt.registerTask('build', ['gitinfo','newer:copy','any-newer:uglify','any-newer:concat','any-newer:cssmin','usemin','newer:imagemin:main']);

Thanks.

@tschaub
Copy link
Owner

tschaub commented Nov 15, 2013

@evanmcd can you see if this test repo works for you?

There could be something else going on with your sequence of tasks, but that simple test works for me.

@tschaub
Copy link
Owner

tschaub commented Nov 18, 2013

@evanmcd please reopen if you can provide some additional information to reproduce your issue. I'm happy to dig into the problem if I can reproduce it.

@tschaub tschaub closed this as completed Nov 18, 2013
@evanmcd
Copy link
Author

evanmcd commented Nov 26, 2013

Hi, sorry for the delay getting back to you. I've submitted a pull request with the update that displays the issue. You'll just need to run

npm install grunt-contrib-copy --save-dev

before running the test again

Not sure what would be causing the issue with copy... strange. Thanks for looking into it.

@tschaub
Copy link
Owner

tschaub commented Nov 26, 2013

Thanks for update. I'll take a look soon.

@tschaub
Copy link
Owner

tschaub commented Dec 5, 2013

Ok, the issue is that your copy task first copies the images from the source to destination directory. When you run the imagemin task with newer, it checks to see if there are any source files that are newer than corresponding destination files. Since you have just copied all source images to the destination directory, the destination files are newer, and there is no work for the newer:imagemin task to do.

The solution is to exclude the images from your copy source files. More generally, you don't want the copy task to copy files that are going to be put in place by another task. If you are going to be comparing timestamps between source and destination files, you don't want multiple tasks overwriting the same destination files.

You could also run the copy task prefixed with newer.

See https://github.com/tschaub/test-grunt-newer-imagemin/commit/e2fac366d2767a4bf2668d7c7f0e439c34c99cd0 for an example of both the copy and imagemin tasks prefixed with newer.

@evanmcd
Copy link
Author

evanmcd commented Dec 12, 2013

OK, I get it now. I didn't realize that the compare newer does is based on two directories. I thought it was based on the history of the file itself, using info saved in a cache file (previously modified date, or size or both perhaps).

Thanks a lot for your help in figuring this out.

@tschaub
Copy link
Owner

tschaub commented Dec 12, 2013

Yeah, I understand the confusion. Here is the logic:

If a task is configured with both src and dest files, the mtime of src files is compared to the mtime of the corresponding dest file. If dest is configured but doesn't exist, all src are considered newer.

If a task is configured with src files only (e.g. a jshint task or anything else that doesn't generate files), the mtime of src files is compared to the last successful run time of the same task. If the task hasn't been run before, all src files are considered newer.

That's it (roughly). I've made some changes to support a new task that compares files based on md5sum (see #5). I'm inclined to call this task different. This would only work by comparing current md5sum calculations for src files to a cached version.

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

2 participants