3 ms·
Interesting, it might solve my dilemna regarding RequireJS vs Browserify given the npm requirejs has one troublesome issue with the paths aliases config getting
by wildpeaks 12y ago
Interesting, it might solve my dilemna regarding RequireJS vs Browserify given the npm requirejs has one troublesome issue with the paths aliases config getting erased (& can't be restored either) once .optimize has been called to make an Almond build. That's why I switched to Browserify in most recent projects, however I have one issue with it and it feels I'm missing something obvious:
What is the right way to use Browserify transforms server-side?
------------------
Because Browerify assumes you use Node's own require() server-side while RequireJS (and now also AMDRequire) have their own module to provide an enhanced require function.
The closest I could come up with (besides giving up and precompiling to a single file before calling Node) is using the deprecated "require.extensions" to preprocess the file, similar to requirejs loaders, e.g. for handlebars you could add in your Node start:
var fs = require('fs');
var Handlebars = require('handlebars');
require.extensions['.handlebars'] = function (module, filename){
var code = fs.readFileSync(filename, 'utf8');
module.exports = Handlebars.compile(code);
};
Then require('./something.handlebars') in modules you share client and server-side gives you the already-compiled template regardless if you're running in Node or in the browser (if you also use the handlebar transforms for Browserify).
I'm sure I'm missing something very obvious here.