[英]jQuery and plugins with webpack (SignalR)
I'm trying to use a JQuery Plugin ( SignalR ) inside my React application.我正在尝试在我的 React 应用程序中使用 JQuery 插件 ( SignalR )。
What I did is :我所做的是:
import $ from 'jquery'
and import 'msSignalrClient'
in the React component I want to.import $ from 'jquery'
和import 'msSignalrClient'
。 But that doesn't seem to work as I get this error : jquery.signalR.min.js?dc9f:9Uncaught Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.
但这似乎不起作用,因为我收到此错误:
jquery.signalR.min.js?dc9f:9Uncaught Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.
jquery.signalR.min.js?dc9f:9Uncaught Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.
One workaround that works is to load in jQuery like this inside my index.html
: <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
.一种有效的解决方法是在我的
index.html
像这样加载 jQuery : <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
。 Of course it's not optimal at all, and I'd like to import jQuery with the method I explained above.当然它根本不是最优的,我想用我上面解释的方法导入jQuery。 Any help appreciated !
任何帮助表示赞赏!
this should work:这应该有效:
npm install jquery signalr expose-loader --save
//inside vendor.ts
import 'expose-loader?jQuery!jquery';
import '../node_modules/signalr/jquery.signalR.js';
我最后做的是这样的:
window.$ = window.jQuery = require("jquery");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.