简体   繁体   English

如何在React.js中使用jQuery依赖节点模块?

[英]How to use a jQuery dependent node module in React.js?

I want to use this library in my React application: http://propeller.in , but it's built on jQuery. 我想在我的React应用程序中使用这个库: http : //propeller.in ,但是它是基于jQuery构建的。 I have added the following relevant code in my Index.js React component: 我在Index.js React组件中添加了以下相关代码:

import $ from 'jquery';
import 'propellerkit/dist/js/propeller.js';

I've also tried this: 我也尝试过这个:

import 'jquery/dist/js/jquery.js';
import 'propellerkit/dist/js/propeller.js';

I've made sure both node modules are installed. 我确保两个节点模块都已安装。 For some reason, I keep getting a $ is not defined error. 由于某种原因,我不断收到$ is not defined错误。

If you are using webpack to bundle, you can provide jquery using ProvidePlugin , 如果您使用的WebPack捆绑,您可以提供jquery使用ProvidePlugin

new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery'   // this will try to find node jquery module
})

Link to docs 链接到文档

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

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