debowerify和coffeeify互动

时间:2014-10-04 13:21:34

标签: twitter-bootstrap bower browserify

当我debowerify使用coffeeify时出现bootstrap无法找到jquery的问题(​​在浏览器错误中):

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安装。

但是当我使用唯一的debowerify没有coffeeify时,引导程序已加载好了:

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

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

问题在于debowerifycoffeeify的互动。如何解决它?

1 个答案:

答案 0 :(得分:0)

解决方案是添加window。在jQuery =之前:

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

现在一切正常。