I'm now trying to use Browserify, and I've got a problem with it.
I always use Backbone with Lodash instead of Underscore, so I wrote some shim scripts for Browserify:
shims/lodash.js
:
'use strict';
/* global window,require,module */
require('../vendor/lodash.underscore-1.2.0');
module.exports = window._;
shims/backbone.js
:
'use strict';
/* global window,require,module */
require('../vendor/backbone-1.0.0');
module.exports = window.Backbone;
app.coffee
:
'use strict'
$ = require './shims/jquery'
_ = require './shims/underscore'
Backbone = require './shims/backbone'
I actually use grunt-coffeeify
to build the Browserify modules, and it says an error below:
Running "coffeeify:source" (coffeeify) task
Warning: module "underscore" not found from "/Users/User/proj/src/js/vendor/backbone-1.0.0.js" Use --force to continue.
What should I change to work Backbone properly? Thanks in advance.
UPDATE
Somehow, it works with codes below:
shims/lodash.js
:
'use strict';
/* global require,module */
module.exports = require('../vendor/lodash-1.2.0');
shims/backbone.js
:
'use strict';
/* global window,require,module */
window.$ = require('./jquery');
window._ = require('./lodash');
module.exports = require('../vendor/backbone-1.0.0');
And comment out code below in backbone-1.0.0.js
:
//if (!_ && (typeof require !== 'undefined')) _ = require('underscore');
This looks something wrong though...
1, lodash published a "Underscore compatible" version. You can use that as a drop-in replacement.
b
is an instance of browserify.
b.require('lodash', {expose: 'underscore'});
for jQuery, look at my version on github : https://github.com/amiorin/jquery
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With