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

时间:2017-08-15 13:25:23

标签: javascript jquery reactjs

我想在我的React应用程序中使用这个库:http://propeller.in,但它是基于jQuery构建的。我在Index.js React组件中添加了以下相关代码:

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

我也试过这个:

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

我确保安装了两个节点模块。出于某种原因,我不断收到$ is not defined错误。

1 个答案:

答案 0 :(得分:1)

如果您使用网络包进行捆绑,则可以使用jquery提供ProvidePlugin

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

链接到docs