添加bootstrap.js到browserify?

所以我想弄清楚如何做到这一点? 我通过凉亭下载了bootstrap-sass,并将bootstrap javascript添加到了一个垫片中。

有几件事让我感到困惑,bootstrap.js文件看起来像这样。

//= require bootstrap/affix //= require bootstrap/alert //= require bootstrap/button //= require bootstrap/carousel //= require bootstrap/collapse //= require bootstrap/dropdown //= require bootstrap/tab //= require bootstrap/transition //= require bootstrap/scrollspy //= require bootstrap/modal //= require bootstrap/tooltip //= require bootstrap/popover 

这是一种自我解释,但同时还是令人困惑的,我是否会这样评论呢? 当我添加到引导程序shim中时,是否只包含bootstrap.js文件,还是应链接到所需的所有文件?

为了避免黑客入侵(我将在此期间进行),我想尝试获取有关如何将bootstrap.js包含到browserify中的信息。

编辑:我想我可能只需要concat所有我需要的文件,并包括该脚本,因为当我浏览bootstrap.js我刚刚得到上述。

我会尝试没有评论,那么如果失败,我会连接所有的脚本到一个文件,看看会发生什么:)

编辑:嗯看起来像concat理论的作品! 唯一的事情是jQuery,看看。

 ; jQuery = global.jQuery = require("c:\\wamp\\www\\mysite\\app\\client\\requires\\jquery\\js\\jquery.js"); /* ======================================================================== * Bootstrap: affix.js v3.1.1 * http://getbootstrap.com/javascript/#affix * ======================================================================== * Copyright 2011-2014 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ 

这是我编译的browserify代码,当我调用一个引导函数,例如$('body').modal('toggle')我必须将上面的jQuery手动更改为$

我尝试在我的垫片内使用,但仍然是我必须手动写$ 。 例

 // Notice I use $ here not jQuery like above, this is the only way to get it to work! ; $ = global.jQuery = require("c:\\wamp\\www\\mysite\\app\\client\\requires\\jquery\\js\\jquery.js"); /* ======================================================================== * Bootstrap: affix.js v3.1.1 * http://getbootstrap.com/javascript/#affix * ======================================================================== * Copyright 2011-2014 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ 

这个答案是由原来的提问者。 它是作为对该问题的编辑发布的。 我把它移到这里,回答的地方。

我重新编译,看起来现在正在工作,确保你的垫片内使用$

 'bootstrap': { "exports": 'bootstrap', "depends": { "jquery": '$' } }, 

另一个解决scheme是使用Webpack ,它有一个脚本加载器来在全局上下文中加载jQuery。