简体   繁体   English

ProvidePlugin不适用于jQuery

[英]ProvidePlugin not working for jquery

I want to include jquery globally to my react application. 我想在我的React应用程序中全局包含jquery。 I am using a lot of third party plugins which uses jquery. 我正在使用很多使用jquery的第三方插件。 So I tried doing it via webpack's ProvidePlugin 所以我尝试通过webpack的ProvidePlugin做到这一点

new webpack.ProvidePlugin({
            React: 'react',
            $: 'jquery',
            jQuery: 'jquery',
            _: 'lodash'
        }),

Now I have removed all the import statements from the components. 现在,我从组件中删除了所有导入语句。 But $ is not mapped to jquery module. 但是$没有映射到jquery模块。 When I do ctrl+click on $, it takes me to dom.js. 当我按ctrl键并单击$时,它将带我到dom.js。 For React:'react', it is working. 对于React:'react',它正在工作。

How can I solve it? 我该如何解决?

These are the errors when I try to run my project 这些是我尝试运行项目时的错误

ion.rangeSlider.js:21 Uncaught ReferenceError: jQuery is not defined
    at ion.rangeSlider.js:21
    at ion.rangeSlider.js:23
(anonymous) @ ion.rangeSlider.js:21
(anonymous) @ ion.rangeSlider.js:23
markers.js:450 Uncaught ReferenceError: jQuery is not defined
    at markers.js:450

That's just a safe way to provide jQuery, etc. to the context of each module during the bundling BUT you must import your jquery inside your code somewhere 这是在捆绑BUT期间向每个模块的上下文提供jQuery等的安全方法,您必须将jquery导入代码中的某个位置

import 'jquery'

or 要么

require('jquery')

If you don't do that, your modules won't be able to consume jQuery 如果您不这样做,则您的模块将无法使用jQuery

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

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