简体   繁体   English

Bootstrap 和 browserify 问题来自 2 个捆绑包

[英]Bootstrap and browserify problems whit 2 bundles

I have a web page with 2 Javascript files, one which is common to all the pages (bundle) and the other one is page-specific thispagespecific.js .我有一个 web 页面,其中包含 2 个 Javascript 文件,一个是所有页面(捆绑包)共有的,另一个是页面特定的thispagespecific.js

In both of them, I must include file bootstrap.js because it is not global and I make use of modal in both of them.在它们中,我必须包含文件bootstrap.js ,因为它不是全局的,并且我在它们中都使用了 modal。

It seems to work without any errors in console but bootstrap component stops working at some point: collapse triggers well, but I can't hide after.它似乎在控制台中没有任何错误,但引导组件在某些时候停止工作:折叠触发很好,但我无法隐藏之后。
First, one bootstrap is executed and the is the other so it will be visible again.首先,一个引导程序被执行,另一个是另一个,因此它将再次可见。

I am thinking about putting Bootstrap global, but I don't know if that is the right way.我正在考虑让 Bootstrap 全球化,但我不知道这是否是正确的方法。

Any help?有什么帮助吗? thanks!谢谢!

HTML HTML

 <script src="../js/bundle.js"></script>
 <script src="../js/thisPageSpecific.js"></script>

main.js ( bundle.js after browserfy) main.js(browserfy后的bundle.js)

var $ = require('jquery');
var bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
//... more requires
$('#menu').modal('show');
//... more code

thisPageSpecific.js thisPageSpecific.js

var $ = require('jquery');
var bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');
$('#pagespecificid').modal('show');
//... more code

At the end i was able to fix my issue whit making bootstrap global and only calling one time.最后,我能够解决我的问题,即让 bootstrap 全球化并且只调用一次。

globalThis.bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js');

This makes global and call boottrap on all pages or even console works.这使得所有页面甚至控制台上的全局和调用引导程序都可以工作。

Maybe is there a cooler solution but.... this works at least for me.也许有更酷的解决方案,但是....这至少对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM