簡體   English   中英

Bootstrap 和 browserify 問題來自 2 個捆綁包

[英]Bootstrap and browserify problems whit 2 bundles

我有一個 web 頁面,其中包含 2 個 Javascript 文件,一個是所有頁面(捆綁包)共有的,另一個是頁面特定的thispagespecific.js

在它們中,我必須包含文件bootstrap.js ,因為它不是全局的,並且我在它們中都使用了 modal。

它似乎在控制台中沒有任何錯誤,但引導組件在某些時候停止工作:折疊觸發很好,但我無法隱藏之后。
首先,一個引導程序被執行,另一個是另一個,因此它將再次可見。

我正在考慮讓 Bootstrap 全球化,但我不知道這是否是正確的方法。

有什么幫助嗎? 謝謝!

HTML

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

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

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

最后,我能夠解決我的問題,即讓 bootstrap 全球化並且只調用一次。

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

這使得所有頁面甚至控制台上的全局和調用引導程序都可以工作。

也許有更酷的解決方案,但是....這至少對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM