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

查看:91
本文介绍了使用引导程序的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');

请参考上面的设置.出现某些错误的原因是"未捕获的ReferenceError:未从dropdown.js定义jQuery()

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 undefined错误. 任何的想法 ?有人可以帮忙解决这个问题吗?

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

非常感谢

推荐答案

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

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天全站免登陆