添加bootstrap.js进行Browserify吗? [英] Adding bootstrap.js to browserify?

查看:102
本文介绍了添加bootstrap.js进行Browserify吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图弄清楚该怎么做?我通过Bower下载bootstrap-sass,并将bootstrap javascript添加到了shim中.

So I am trying to figure out how to do this? I downloaded bootstrap-sass via bower and added the bootstrap javascript into a shim.

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

A few things have me confused, the bootstrap.js file looks like this.

//= 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填充程序时,是否仅包含bootstrap.js文件,还是应该链接到所需的所有文件?

This is kind of self explanatory, but still confusing at the same time, do I leave it commented like that? When I add to the bootstrap shim do I include just the bootstrap.js file, or should I link to all the ones I need?

只是为了保护自己免遭黑客入侵(同时我将做),我想尝试获得一些有关如何将bootstrap.js包含到browserify中的信息.

Just to save myself from hacking away (which I will be doing in the meantime), I'd like to try to get some information on how to include bootstrap.js into browserify.

我想我可能只需要合并所有需要的文件并包含该脚本,因为当我浏览bootstrap.js时,我得到了上面的内容.

I think I might just have to concat all the files I need and include that script, because when I browserify the bootstrap.js I just get the above.

我将尝试不添加注释,如果失败,我将所有脚本合并到一个文件中,然后看看会发生什么:)

I'll try without the comments, then if that fails I'll concat all the scripts into one file and see what happens :)

嗯,就像concat理论在起作用!唯一的是jQuery,看看吧.

Hmm looks like the concat theory works! The only thing is jQuery, take a look.

; 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更改为$.

This is my compiled browserify code, the only way to get it to work when I call a bootstrap function say for example $('body').modal('toggle') I have to change the jQuery above to $ manually.

我尝试在垫片内部同时使用这两种方法,但仍然必须手动编写$.例子

I tried using both inside my shim but still same thing I must manually write $. Example

// 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)
 * ======================================================================== */

推荐答案

此答案由原始提问者提供.它被发布为对问题的编辑.我把它移到了这里,答案就去了.

This answer is by the original questioner. It was posted as an edit to the question. I moved it here, where the answers go.

我重新编译,看来现在可以正常使用了,请确保您的内部 匀称您使用$

I recompiled and it looks like it's working now, make sure inside your shim you use $

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

这篇关于添加bootstrap.js进行Browserify吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆