2013-04-17 15 views
6

Ich versuche jetzt, Browserify zu verwenden, und ich habe ein Problem damit.Backbone mit Lodash anstelle von Underscore und Browserify

ich immer Backbone mit Lodash anstelle von Unterstrichen, also schrieb ich einige Shim-Skripte für 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' 

Ich benutze grunt-coffeeify tatsächlich die Browserify Module zu bauen, und es sagt, einen Fehler unter:

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. 

Was soll ich ändern richtig Backbone zu arbeiten? Danke im Voraus.

UPDATE

Irgendwie funktioniert es Codes mit unter:

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'); 

Und Code unten in 012.377 auf Kommentar:

//if (!_ && (typeof require !== 'undefined')) _ = require('underscore'); 

Diese ...

Antwort

3

b wenn etwas falsch aussieht, ist eine Instanz von browserify.

b.require('lodash', {expose: 'underscore'}); 

für jQuery, um meine Version auf GitHub aussehen: https://github.com/amiorin/jquery

+0

Das hat bei mir nicht funktioniert. Könnten Sie diese Technik erweitern? – rattray

0

Sie brauchen keine Unterlegscheiben. Alles was Sie brauchen ist ein korrekter Alias ​​in der browserify Aufgabe.

alias: ['./node_modules/lodash/dist/lodash.underscore.js:underscore'] 

Look at my example