使用引导程序的 Webpack - 未定义 jquery [英] Webpack using bootstrap - jquery is not defined

查看:21
本文介绍了使用引导程序的 Webpack - 未定义 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import $ from 'jquery';
require("./node_modules/bootstrap/dist/css/bootstrap.min.css")
require("./node_modules/bootstrap/js/dropdown.js")
import React from 'react';
import ReactDOM from 'react-dom';
var _ = require('lodash');

请参考上面我的设置.某些原因我收到错误消息Uncaught ReferenceError: jQuery is not defined() from dropdown.js

Please refer above my setting . Some reason I've got error saying "Uncaught ReferenceError: jQuery is not defined() from dropdown.js

我还在 webpack.config.js 中加入了以下几行

I also included the following lines at webpack.config.js

   plugins: [
    new webpack.NoErrorsPlugin({
        $: "jquery",
        jQuery: "jquery"
    })
]

但是,运气不好 - 仍然有 jQuery 未定义错误.任何的想法 ?有人可以帮忙解决这个问题吗?

But, No luck - Still having jQuery undefined error. Any idea ? Can someone help this issue please?

非常感谢

推荐答案

请使用 webpack ProviderPlugin,使用 global 不是一个好主意.

please use webpack ProviderPlugin, use global is not a good idea.

// webpack.config.js
module.exports = {
    ...
    plugins: [
        new webpack.ProvidePlugin({
           $: "jquery",
           jQuery: "jquery"
       })
    ]
};

这篇关于使用引导程序的 Webpack - 未定义 jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆