Add usemin option
ericclemmons opened this issue · 16 comments
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.
@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]
@ericclemmons nevermind, that was due to a leftover concat
property
@ericclemmons Not getting any errors now, but it doesn't seem like it's actually getting concatenated to application.js
@pheuter I assume @ericclemmons have to fix this issue first to make it work :)
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?
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
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? :)
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. =/
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.
@marcalj Thanks, but unfortunately I've got 2 js groups... Also I've just noticed that I've got rev
task running after ngtemplates
...
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!
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
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!
@ericclemmons Thanks Eric! Much appreciated. 👍
@ericclemmons Works perfectly! Excellent job! :)
I'll leave this here in case someone is looking into how make grunt-rev
work with grunt-angular-templates