At the time this question was asked, the most recent version of grunt-modernizr
would have been 0.4.1. Assuming that the OP was using the most recent version:
Adding community tests in version 0.4.1
The README shows two (optional) options of interest:
tests
(Array)
Define any tests you want to implicitly include. Test names are lowercased, separated by underscores (if needed). Check out the full set of test options here.
And:
matchCommunityTests
(Boolean)
When parseFiles
= true
, setting this boolean to true will attempt to match user-contributed tests. Check out the full set of community tests here
You will notice that the list of available tests that one can add to the tests
array includes both core and community tests. Thus, if you want to explicitly include particular community tests, you can enumerate them in the tests
array option. For example:
// This would be in a larger config file
tests: ["a_download", "css_remunit"]
But if you have parseFiles
set to true and want grunt-modernizr
to detect any community tests that you have, you can set matchCommunityTests
to true.
The posted config for grunt-modernizr
does not included either of the options, and if the OP wanted to use Modernizr.getusermedia
, they could simply set the tests
array to include "getusermedia"
:
modernizr: {
devFile: '<%= yeoman.app %>/components/modernizr/modernizr.js',
outputFile: '<%= yeoman.dist %>/components/modernizr/modernizr.js',
extra: {
'shiv' : true,
'printshiv' : false,
'load' : true,
'mq' : false,
'cssclasses' : true
},
extensibility: {
'addtest': true,
'prefixed': false,
'teststyles': false,
'testprops': false,
'testallprops': false,
'hasevents': false,
'prefixes': false,
'domprefixes': false
},
files: [
'<%= yeoman.dist %>/scripts/{,*/}*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'!<%= yeoman.dist %>/scripts/vendor/*'
],
uglify: true,
// Explicitly include the `getusermedia` test
tests: ['getusermedia']
}
Currently, grunt-modernizr
is at version 0.5.2. One significant change from the OP is that the Modernizr
task is now a multi-task.
Adding community tests in 0.5.2
The README still offers two (optional) options of interest:
tests
(Array)
Define any tests you want to implicitly include. Test names are lowercased, separated by underscores (if needed). Check out the full set of test options here.
And:
matchCommunityTests
(Boolean)
When parseFiles
= true
, setting this boolean to true will attempt to match user-contributed tests. Check out the full set of community tests here
With this information, we know that we can define the task as follows:
modernizr: {
dist: {
devFile: '<%= yeoman.app %>/components/modernizr/modernizr.js',
outputFile: '<%= yeoman.dist %>/components/modernizr/modernizr.js',
extra: {
'shiv' : true,
'printshiv' : false,
'load' : true,
'mq' : false,
'cssclasses' : true
},
extensibility: {
'addtest': true,
'prefixed': false,
'teststyles': false,
'testprops': false,
'testallprops': false,
'hasevents': false,
'prefixes': false,
'domprefixes': false
},
uglify: true,
tests: ['getusermedia']
}
}
Where setting the tests
array to include 'getusermedia'
will always include the community getusermedia
test.
Automatically detecting community tests
(See #67, #85, #86, #87, and #88.)
Automatic detection of community tests is buggy. It seems that regardless of what matchCommunityTests
is set to, false
or true
, community tests that exist will be downloaded and included in the custom build. For example, this basic task config:
modernizr: {
dist: {
devFile: 'vendor/modernizr/modernizr.js',
outputFile: 'js/modernizr.custom.js',
uglify: false,
files: {
src: ['js/src/**/*.js']
}
}
}
And this simple JS file:
;(function (
window,
document,
Modernizr
) {
if (Modernizr.touch) {}
if (Modernizr.cookies && Modernizr.cors && Modernizr.gamepad) {}
}(
window,
window.document
Modernizr
));
Results in a custom build that does include tests for cookies
, cors
, and gamepad
: download link.