[英]Adding bootstrap.js to browserify?
所以我想弄清楚如何做到这一点? 我通过bower下载了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
这是一种自我解释,但同时仍然令人困惑,我是否会这样评论? 当我添加到bootstrap shim时,我只包含bootstrap.js文件,还是应该链接到我需要的所有文件?
为了避免被黑客攻击(我将在此期间进行),我想尝试获取有关如何将bootstrap.js包含在browserify中的一些信息。
编辑:我想我可能只需要连接我需要的所有文件并包含该脚本,因为当我浏览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)
* ======================================================================== */
这是我编译的浏览器代码,当我调用bootstrap函数时让它工作的唯一方法就是说例如$('body').modal('toggle')
我必须将上面的jQuery
更改为$
manual。
我尝试在我的垫片内使用两者但仍然是同样的事情我必须手动写$
。 例
// 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": "$" } },
另一个解决方案是使用Webpack ,它有一个脚本加载器来在全局上下文中加载jQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.