gulp-modernizr
gulp-modernizr copied to clipboard
Any of of 'requirejs' breaks build.
If any other module uses the requirejs api after gulp-modernizr is imported, eg:
var requirejs = require('requirejs');
requirejs.optimize({
mainConfigFile: config.js + '/bootstrap.js',
out: 'app.js',
name: 'foo'
}, function(err) {
if (err) {
console.log(err);
}
console.log("Done");
});
Or, for example, using https://github.com/jlouns/gulp-requirejs-optimize ...
Then the build will fail like this:
Looking for Modernizr references
>> 1 match in /Users/doug/dev/empty-coop/foo/static/build/stylesheets/_manifest.css
>> svg
>> 1 match in /Users/doug/dev/empty-coop/foo/static/build/stylesheets/styles-nomq.css
>> svg
>> 1 match in /Users/doug/dev/empty-coop/foo/static/build/stylesheets/styles.css
>> svg
>> Ready to build using these settings:
>>
Building your customized ModernizrGenerate in call: undefined
undefined
TAP version 13
not ok 1 - TypeError: generate is not a function
---
at:
line: 69
column: 25
file: node_modules/modernizr/lib/build.js
function: build
stack: >
build (node_modules/modernizr/lib/build.js:69:25)
Object.build (node_modules/modernizr/lib/build.js:162:50)
Object.init (node_modules/customizr/src/builder.js:101:14)
next (node_modules/promised-io/promise.js:584:17)
notify (node_modules/promised-io/promise.js:201:22)
notifyAll (node_modules/promised-io/promise.js:180:5)
[object Object].Deferred.resolve.callback.emitSuccess
(node_modules/promised-io/promise.js:223:3)
[object Object]._onTimeout (node_modules/customizr/src/crawler.js:250:22)
test: TAP
message: 'TypeError: generate is not a function'
source: |
'modernizr-init': generate(config)
...
1..1
# failed 1 of 1 tests
# time=3426.104ms
This is because https://github.com/Modernizr/Modernizr/blob/master/lib/build.js#L154 fails to resolve anything, presumably because requirejs is initialized when the gulp-modernizr package is initially imported, and then somehow screwed up when something uses it.
I don't have any solution to this other than, 'Don't use anything that uses requirejs in your build', but I thought I'd report this here (even though technically the problem is in modernizr, not gulp-modernizr), so that frustrated folks could find it easily.
Same issue here.
@cibulka You can see the workaround we ended up using here https://github.com/hatchddigital/empty-coop/blob/master/gulp/tasks/scripts.js#L72
Basically using exec to invoke the external requirejs builder; but probably a better long term solution is just to stop using requirejs. :P
Anyhow, hope that helps.
@shadowmint Thank you! After the pain I had with the setup of my Requirejs workflow, I think I will have to use it for a while :), so for now, I settled with using Modernizr directly from command line.
Thanks for the info, I'm definitely trying the workaround later!
For now, I've resorted to use https://github.com/shinnn/modernizr-stream, so I can use Modernizr's command line along with my Gulp workflow. Maybe someone finds that useful ...