我現在正在嘗試使用Browserify,並且我遇到了問題。Backod與Lodash而不是Underscore和Browserify
我總是用骨幹與Lodash而不是下劃線,所以我寫了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'
實際上我用grunt-coffeeify
打造Browserify模塊,和它說的錯誤如下:
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.
我應該改變工作骨幹正常嗎?提前致謝。
UPDATE
不知怎的,它的工作原理下面的代碼:
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');
而且在下面註釋掉的代碼:
//if (!_ && (typeof require !== 'undefined')) _ = require('underscore');
這看起來是錯誤的,但...
這並沒有爲我工作。你可以擴展這種技術嗎? – rattray