2014-10-04 51 views
0

當我使用debowerifycoffeeify得到了bootstrap找不到的jQuery(瀏覽器錯誤)問題:debowerify和coffeeify互動

Uncaught Error: Bootstrap's JavaScript requires jQuery bootstrap.js:7 

在我的source.coffee文件是:

$ = jQuery = require ('jquery') 
require('bootstrap') 
bootstrap_enabled = (typeof $().modal == 'function') 
console.log "bootstrap_enabled" 
console.log bootstrap_enabled 

的package.json:

{ 
    "name": "bootstrap_test", 
    "version": "0.0.1", 
    "private": true, 
    "scripts": { 
    "main": "browserify source.coffee -t coffeeify -t debowerify > main.js --debug" 
    }, 
    "bootstrap": { 
    "depends": [ 
     "jquery:$" 
    ] 
    }, 
    "dependencies": {}, 
    "devDependencies": { 
    "browserify": "^6.0.2", 
    "coffeeify": "^0.7.0", 
    "debowerify": "^0.8.2" 
    } 
} 

jquerybootstrap通過bower安裝。

但是,當我使用的唯一debowerifycoffeeify引導加載OK:

$ = jQuery = require ('jquery'); 
require('bootstrap'); 

browserify source.js -t debowerify > main.js --debug 

所以問題是在debowerifycoffeeify互動。如何解決它?

回答

0

解決方法是添加windowjQuery =

$ = window.jQuery = require ('jquery') 
require('bootstrap') 
bootstrap_enabled = (typeof $().modal == 'function') 
console.log "bootstrap_enabled" 
console.log bootstrap_enabled 

現在一切正常。