I have done some initial investigation and there appears to be a definite problem with the preamble. I've raised an issue with the grunt-browserify maintainers so lets see what comes of that.
For now I am concatenating a file between vendor.js and app.js as a way to fix the preamble as follows:
Gruntfile.js
concat: {
'build/<%= pkg.name %>.js': ['build/vendor.js', 'client/src/fix_browserify', 'build/app.js']
},
fix_browserify
require=
Note there is no carriage return or linefeed in the above file
I am unsure if there will be any unintended consequences of defining require
twice but it appears to be working in my limited use. If you have more than just one app bundle then you would similarly need to interleave concatenation of the fix_browserify
file before each of the bundles.
If I become aware of any better solutions I'll update this answer.
UPDATE
I ended up ditching grunt/browserify after looking at how browerify worked and just went with brunch which was far easier to setup and also does much faster rebuilds when things change. Whilst not a grunt replacement it builds everything I need.