Should Brunch compile Node.js modules to AMD, Common.js, Node.js and Browser-compatible single file?
See original GitHub issueWe recently launched BackboneORM which needs to run in the Browser and in Node.js.
I modified Brunch’s module system in a way similar to how Superagent delivers a AMD, Common.js, Node.js and Browser-compatible single file. Basically, you would define a local module system and then expose the root symbol and its dependencies in multiple loader-compatibile formats:
if (typeof exports == 'object') {
module.exports = require('backbone-orm/lib/index');
}
else if (typeof define == 'function' && define.amd) {
define('backbone-orm', ['underscore', 'backbone', 'moment', 'inflection'], function(){return require('backbone-orm/lib/index'); });
}
else {
window.bborm = require('backbone-orm/lib/index');
}
Also, I added a shim method so the bundle can load dependencies from AMD, Browserified, or pull things off of window when loading in the browser.
if window?
require.shim([
{symbol: '_', path: 'lodash', alias: 'underscore', optional: true}, {symbol: '_', path: 'underscore'}
...
])
Do achieve this, I combined a grunt script and Brunch config.
I think it would be reasonably simple to add some library building config options to Brunch; for example, listing AMD dependencies. What would you think about adding this support natively to Brunch?
Input: Many files including CoffeeScript which use of Common.js Output: AMD, Common.js, Node.js and Browser-compatible single file
Issue Analytics
- State:
- Created 10 years ago
- Comments:19 (13 by maintainers)
Top GitHub Comments
@pcattori, I’d rather look at babel compiler and/or webpack. If you publish your package to npm, you might not necessarily want to concatenate it into a single file - then use babel compiler directly just to translate it to ES5. Webpack can easily build UMD package that can be published too. I’ve switched to these tools and they seem to be really popular in React’s world.
yeah we’ll need to investigate different ways of solving this problem. i’ve meant that “AMD” and “browser-compatible” files are no longer really needed. Something to bundle it to one commonjs module would be useful.