grunt-angular-templates
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -92,7 +92,7 @@ /* | ||
custom_concat_usemin: { | ||
custom_usemin: { | ||
src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'], | ||
dest: 'tmp/custom_concat_usemin.js', | ||
options: { | ||
concat: 'generated' | ||
usemin: 'usemin/all.js' | ||
} | ||
@@ -99,0 +99,0 @@ }, |
{ | ||
"name": "grunt-angular-templates", | ||
"description": "Grunt build task to concatenate & register your AngularJS templates in the $templateCache", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"homepage": "https://github.com/ericclemmons/grunt-angular-templates", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -158,3 +158,9 @@ # grunt-angular-templates | ||
### usemin | ||
> Path to `<!-- build:js [path/to/output.js] -->` usemin target | ||
This should be the output path of the compiled JS indicated in your HTML, | ||
such as `path/to/output.js` shown here. | ||
## Usage | ||
@@ -208,9 +214,11 @@ | ||
```html | ||
<!-- build:js combined.js --> | ||
<!-- build:js dist/vendors.js --> | ||
<script src="bower_components/angular/angular.js"></script> | ||
<script src="bower_components/angular-resource/angular-resource.js"></script> | ||
<!-- endbuild --> | ||
``` | ||
The name of your `build:js` file automatically becomes the `concat` target | ||
name. So, simply just copy/paste that name into the `concat` option: | ||
**Do not use the `concat` option**, even though grunt-usemin generates a `concat.generated` | ||
object behind the scenes. Instead, use the `usemin` option to indicate the anticipated | ||
output filepath from grunt-usemin. | ||
@@ -223,3 +231,3 @@ ```js | ||
options: { | ||
concat: 'combined.js' | ||
usemin: 'dist/vendors.js' // <~~ This came from the <!-- build:js --> block | ||
} | ||
@@ -230,2 +238,7 @@ } | ||
**Note**: Earlier versions of grunt-usemin (*correctly, in my opinion*) would have generated | ||
a `concat['dist/vendors.js']` object for each build section in the HTML. Now, | ||
because there's a single `concat.generated` object with **all** JS/CSS files within it, | ||
I'm back-tracking the proper `concat` target for you. | ||
## Examples | ||
@@ -340,3 +353,5 @@ | ||
- v0.5.1 – Add `usemin` option form v0.4.10 | ||
- v0.5.0 – Works with `grunt-usemin` ([#44](https://github.com/ericclemmons/grunt-angular-templates/issues/44)) | ||
- v0.4.10 – Add `usemin` option | ||
- v0.4.9 – Improve `prefix` and support for URLs ([#57](https://github.com/ericclemmons/grunt-angular-templates/pull/57)) | ||
@@ -343,0 +358,0 @@ - v0.4.8 – Compiled assets are JSHint-able ([#58](https://github.com/ericclemmons/grunt-angular-templates/pull/58)) |
@@ -12,4 +12,3 @@ /* | ||
var Compiler = require('./lib/compiler'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
var Appender = require('./lib/appender'); | ||
@@ -32,3 +31,3 @@ module.exports = function(grunt) { | ||
grunt.registerMultiTask('ngtemplates', 'Compile AngularJS templates for $templateCache', function() { | ||
var ngtemplatesTask = function() { | ||
var options = this.options({ | ||
@@ -43,3 +42,4 @@ angular: 'angular', | ||
standalone: false, | ||
url: function(path) { return path; } | ||
url: function(path) { return path; }, | ||
usemin: null, | ||
}); | ||
@@ -55,2 +55,3 @@ | ||
var compiler = new Compiler(grunt, options, file.cwd); | ||
var appender = new Appender(grunt); | ||
var modules = compiler.modules(file.src); | ||
@@ -66,49 +67,18 @@ var compiled = []; | ||
// Append file.dest to specified concat target | ||
if (options.concat) { | ||
if (process.platform === 'win32') { | ||
options.concat = options.concat.replace(/\//g, '\\'); | ||
if (options.usemin) { | ||
if (appender.save('generated', appender.concatUseminFiles(options.usemin, file))) { | ||
grunt.log.writeln('Added ' + file.dest.cyan + ' to ' + ('<!-- build:js ' + options.usemin + ' -->').yellow); | ||
} | ||
} | ||
var config = grunt.config(['concat', options.concat]); | ||
if (!config) { | ||
grunt.log.warn('Concat target not found: ' + options.concat.red); | ||
return false; | ||
if (options.concat) { | ||
if (appender.save(options.concat, appender.concatFiles(options.concat, file))) { | ||
grunt.log.writeln('Added ' + file.dest.cyan + ' to ' + ('concat:' + options.concat).yellow); | ||
} | ||
// Grunt handles files 400 different ways. Not me. | ||
var normalized = grunt.task.normalizeMultiTaskFiles(config, options.concat); | ||
// Only work on the original src/dest, since files.src is a [GETTER] | ||
var originals = normalized.map(function(files) { | ||
return files.orig; | ||
}); | ||
// Append output templates to only .JS targets | ||
var modified = originals.map(function(files) { | ||
var jsFiles = files.src.filter(function(file) { | ||
return '.js' === file.substr(-3); | ||
}); | ||
if (jsFiles.length) { | ||
files.src.push(file.dest); | ||
} | ||
return files; | ||
}); | ||
// Re-save processed concat target | ||
grunt.config(['concat', options.concat], { | ||
files: originals, | ||
options: config.options || {} | ||
}); | ||
grunt.log.writeln('Added ' + file.dest.cyan + ' to ' + ('concat:' + options.concat).yellow); | ||
} | ||
}); | ||
}); | ||
}; | ||
grunt.registerMultiTask('ngtemplates', 'Compile AngularJS templates for $templateCache', ngtemplatesTask); | ||
}; |
@@ -38,7 +38,9 @@ 'use strict'; | ||
custom_concat_usemin: function(test) { | ||
test.expect(3); | ||
custom_usemin: function(test) { | ||
test.expect(5); | ||
test.equal(grunt.file.read('test/expected/usemin.html'), grunt.file.read('tmp/usemin.html')); | ||
test.equal(grunt.file.read('test/expected/usemin/foo.js'), grunt.file.read('tmp/usemin/foo.js')); | ||
test.equal(grunt.file.read('test/expected/usemin/foo.js').slice(0, -1), grunt.file.read('tmp/usemin/foo.js')); | ||
test.equal(grunt.file.read('test/expected/usemin/bar.js').slice(0, -1), grunt.file.read('tmp/usemin/bar.js')); | ||
test.equal(grunt.file.read('test/expected/usemin/all.js').slice(0, -1), grunt.file.read('tmp/usemin/all.js')); | ||
test.equal(grunt.file.read('test/expected/usemin/bar.css'), grunt.file.read('tmp/usemin/bar.css')); | ||
@@ -45,0 +47,0 @@ |
@@ -1,1 +0,1 @@ | ||
var Foo=function(){};angular.module("custom_concat_usemin").run(["$templateCache",function(a){"use strict";a.put("test/fixtures/one.html",'<h1>One</h1>\n\n<p class="">I am one.</p>\n\n<script type="text/javascript">\n // Test\n /* comments */\n var foo = \'bar\';\n</script>\n'),a.put("test/fixtures/two/two.html",'<h2>Two</h2>\n\n<!-- Comment for two -->\n\n<textarea readonly="readonly">We are two.</textarea>\n')}]); | ||
var Foo=function(){}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50156
43
1025
399