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

Add usemin option #63

Closed
ericclemmons opened this issue Dec 2, 2013 · 16 comments
Closed

Add usemin option #63

ericclemmons opened this issue Dec 2, 2013 · 16 comments
Assignees

Comments

@ericclemmons
Copy link
Owner

From @pheuter:

@ericclemmons In my case, I am generating two javascript files, vendor.js and application.js. When concatenating ng-templates, I need to append solely to application.js. The error I was running into was due to the templates file being concatenated to both files and that caused errors.

// build:js(.) javascripts/vendor.js

// build:js(.) javascripts/application.js

In which case, the jump to 0.5.0 may not be warranted (whoops!), because this solution can let someone specify usemin: 'javascripts/application.js' to target that specific dest.

concat is useful if you have a specific concat task, but trying to target what usemin generates for concat is annoying at best.

@pheuter
Copy link

pheuter commented Dec 2, 2013

@ericclemmons I'm getting the following error now:

Running "ngtemplates:dist" (ngtemplates) task
File resources/views.js created.
>> Concat target not found: generated.files[3]

@pheuter
Copy link

pheuter commented Dec 2, 2013

@ericclemmons nevermind, that was due to a leftover concat property

@pheuter
Copy link

pheuter commented Dec 2, 2013

@ericclemmons Not getting any errors now, but it doesn't seem like it's actually getting concatenated to application.js

@marcalj
Copy link

marcalj commented Dec 3, 2013

@pheuter I assume @ericclemmons have to fix this issue first to make it work :)

@paulyoung
Copy link

I'm confused about the status of this issue. It appears that @ericclemmons fixed something in #44 which should have fixed @pheuter's use case.

@pheuter - are you saying that it doesn't?

@ericclemmons
Copy link
Owner Author

I attempted to fix it in #44, but there was another edge case to be resolved here ;) The good news is, this will be BC-compatible with 0.4.x

@szimek
Copy link

szimek commented Dec 4, 2013

I'm currently trying to set it up using v0.5.0 and I'm getting Concat target not found: scripts/scripts.js error. I guess I should just wait for usemin option then? :)

@ericclemmons
Copy link
Owner Author

Wait, everyone just wait! :) Go to #63 now. concat works with legit concat targets, but usemin screwed the pooch with how they're doing things now. =/

@marcalj
Copy link

marcalj commented Dec 4, 2013

tl;dr If you just create a sigle js file with usemin use generated as concat target.

@szimek You have to use generated as concat target:

ngtemplates:  {
      dist: {
        cwd: '<%= yeoman.app %>',
        src: 'views/**.html',
        dest: '<%= yeoman.dist %>/scripts/templates.js',
        options: {
          module: 'app', // Can replace ngtemplates.dist with ngtemplates.app
          concat: 'generated',
//          htmlmin:  { collapseWhitespace: true, collapseBooleanAttributes: true },
          htmlmin: {}
        }
      }
    },

But this will concat templates for all js groups.

@szimek
Copy link

szimek commented Dec 4, 2013

@marcalj Thanks, but unfortunately I've got 2 js groups... Also I've just noticed that I've got rev task running after ngtemplates...

@ericclemmons
Copy link
Owner Author

Yep, let's wait for this issue to get fixed, then. Everyone be sure to thank grunt-usemin for changing how it builds concat targets now!

@szimek
Copy link

szimek commented Dec 6, 2013

Here's a small snippet that adds usemin option:

if (options.usemin) {
  var _ = grunt.util._;
  var config = grunt.config('concat');
  var prefix = '.tmp/concat/';

  var files = _.find(config.generated.files, function (item) {
    return item.dest === prefix + options.usemin;
  });

  files.src.push(file.dest);

  grunt.config('concat', {
    generated: { files: config.generated.files }
  });
}

It doesn't handle errors (i.e. invalid path to destination file in concat configuration) and I'm not sure how to read prefix path from usemin configuration, but it works. It doesn't solve the issue that usemin updates paths in HTML files to files renamed by rev after these HTML files are processed by ngtemplates.

Here's commit with these changes: szimek@1235cd4

@ghost ghost assigned ericclemmons Dec 16, 2013
@ericclemmons
Copy link
Owner Author

Just released v0.4.10 & v0.5.1 to be effectively the same thing, which adds a usemin option. Check out the updated README & release!

@danielmcormond
Copy link

@ericclemmons Thanks Eric! Much appreciated. 👍

@marcalj
Copy link

marcalj commented Dec 16, 2013

@ericclemmons Works perfectly! Excellent job! :)

@orlando
Copy link

orlando commented Feb 21, 2014

I'll leave this here in case someone is looking into how make grunt-rev work with grunt-angular-templates

yeoman/grunt-usemin#235 (comment)

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

7 participants