首页 > 解决方案 > 如何在编译的 npm webpack 文件中使用 jquery 函数而不将 jquery 导入编译输出

问题描述

我正在使用 bootstrap 4,并且正在将 bootstrap 编译为最终theme.js输出文件,以整合我所有的自定义 js 和其他节点供应商。

但我想通过这样的 CDN 将我的 jQuery 单独加载到标题中......

<!DOCTYPE html>
<html>
  <head>
     <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  </head>
  <body>
     <script src="../dist/js/theme.js"></script>
  </body>
</html>

所以我然后像这样处理我的进口theme.js......

require('bootstrap');
require('popper.js');
require('bootstrap-select');
require('slick-carousel');
require('scrollreveal');
require('lightgallery');

// document ready
(function ($) {

    // automatically show the popup
    $('#welcomePopup').modal('show');

})(jQuery);

这编译得很好,没有错误。但是在我的网站上运行时,我在控制台中收到此错误theme.js...

在此处输入图像描述


我真的不想将 jQuery 编译到我的theme.js. 有解决方案吗?

我试过使用jquery-bridget但这没有用。无论如何,我认为这不是正确的工具。我真的可以使用一些友好的建议谢谢。

标签: jquerynpmwebpack

解决方案


推荐阅读