diff --git a/tasks/usemin.js b/tasks/usemin.js
index 21ad81b..d3946ce 100644
--- a/tasks/usemin.js
+++ b/tasks/usemin.js
@@ -110,15 +110,15 @@ module.exports = function (grunt) {
});
var blockReplacements = options.blockReplacements || {};
- debug('Looking at %s target', this.target);
-
+ var type = options.type;
var patterns = [];
- var type = this.target;
+
+ debug('Looking at %s target', type);
// Check if we have a user defined pattern
- if (options.patterns && options.patterns[this.target]) {
- debug('Adding user defined patterns for %s', this.target);
- patterns = options.patterns[this.target];
+ if (options.patterns && options.patterns[type]) {
+ debug('Adding user defined patterns for %s', type);
+ patterns = options.patterns[type];
}
// var locator = options.revmap ? grunt.file.readJSON(options.revmap) : function (p) { return grunt.file.expand({filter: 'isFile'}, p); };
@@ -158,11 +158,14 @@ module.exports = function (grunt) {
});
grunt.registerMultiTask('useminPrepare', 'Using HTML markup as the primary source of information', function () {
- var options = this.options();
+ var options = this.options({
+ type: this.target
+ });
// collect files
var dest = options.dest || 'dist';
var staging = options.staging || '.tmp';
var root = options.root;
+ var type = options.type;
if (!this.filesSrc.length) {
grunt.fail.warn('No source file found.');
diff --git a/test/test-usemin-prepare.js b/test/test-usemin-prepare.js
index 0dee425..7a2358f 100644
--- a/test/test-usemin-prepare.js
+++ b/test/test-usemin-prepare.js
@@ -366,4 +366,67 @@ describe('useminPrepare', function () {
assert.equal(options.foo, 'bar');
});
+
+ describe('multiple target support', function () {
+ before(helpers.directory('temp'));
+
+ it('should honor type option', function () {
+ grunt.log.muted = true;
+ grunt.config.init();
+ grunt.config('useminPrepare', {
+ foohtml: {
+ files: {
+ src: ['index.html']
+ },
+ options: {
+ type: 'html'
+ }
+ }
+ });
+
+ grunt.file.copy(path.join(__dirname, 'fixtures/usemin.html'), 'index.html');
+ grunt.file.copy(path.join(__dirname, 'fixtures/style.css'), 'styles/main.css');
+ grunt.file.mkdir('scripts');
+ grunt.file.write('scripts/bar.js', 'bar');
+ grunt.file.write('scripts/baz.js', 'baz');
+ grunt.file.mkdir('scripts/vendor');
+ grunt.file.mkdir('scripts/vendor/bootstrap');
+ grunt.file.write('scripts/vendor/bootstrap/bootstrap-affix.js', 'bootstrap-affix');
+ grunt.file.write('scripts/vendor/bootstrap/bootstrap-alert.js', 'bootstrap-alert');
+
+ grunt.task.run('useminPrepare');
+ grunt.task.start();
+
+ // we only test that default flow has been applied
+ var concat = grunt.config('concat');
+ assert.equal(concat.generated.files.length, 2);
+
+ var uglify = grunt.config('uglify');
+ assert.equal(uglify.generated.files.length, 1);
+
+ var cssmin = grunt.config('cssmin');
+ assert.equal(cssmin.generated.files.length, 1);
+ });
+
+ it('should not warn if no type option provided and target not known', function () {
+ grunt.log.muted = true;
+ grunt.config.init();
+ grunt.config('useminPrepare', {
+ foohtml: 'index.html'
+ });
+
+ grunt.task.run('useminPrepare');
+ grunt.task.start();
+
+ // we only test that default flow has been applied
+ var concat = grunt.config('concat');
+ assert.equal(concat.generated.files.length, 2);
+
+ var uglify = grunt.config('uglify');
+ assert.equal(uglify.generated.files.length, 1);
+
+ var cssmin = grunt.config('cssmin');
+ assert.equal(cssmin.generated.files.length, 1);
+ });
+ });
});
diff --git a/test/test-usemin.js b/test/test-usemin.js
index 561085a..0796111 100644
--- a/test/test-usemin.js
+++ b/test/test-usemin.js
@@ -353,4 +353,35 @@ describe('usemin', function () {
// Check replace has performed its duty
assert.ok(changed.match(''));
});
+
+ it('should honor options.type', function () {
+ grunt.file.mkdir('build');
+ grunt.file.mkdir('build/images');
+ grunt.file.mkdir('build/images/misc');
+ grunt.file.write('build/images/test.23012.png', 'foo');
+ grunt.file.write('build/images/bar.23012.png', 'foo');
+ grunt.file.write('build/images/misc/test.2a436.png', 'foo');
+ grunt.file.copy(path.join(__dirname, 'fixtures/htmlprocessor_absolute.html'), 'build/index.html');
+
+ grunt.log.muted = true;
+ grunt.config.init();
+ grunt.config('usemin', {
+ foohtml: {
+ files: {
+ src: ['build/index.html']
+ },
+ options: {
+ type: 'html'
+ }
+ }
+ });
+ grunt.task.run('usemin');
+ grunt.task.start();
+
+ var changed = grunt.file.read('build/index.html');
+
+ assert.ok(changed.match(//));
+ assert.ok(changed.match(//));
+ assert.ok(changed.match(//));
+ });
});