webpack jquery and angular - jQuery not defined

孤街浪徒 提交于 2019-12-11 00:17:47

问题


I'm refactoring an existing project into webpack. The project uses angular (1.3) and jQuery (2.1). On the initial web page there are already some jQuery functions being called but these fail because 'jQuery is not defined'. Even after loading the page (via console) jQuery stays undefined. '$' is defined but I'm not sure if it's actually pointing to jQuery.

I adapted the webpack config to expose the jquery variables in all modules (as explained here and in several posts):

    new webpack.ProvidePlugin({
       $: "jquery",
       'window.jQuery': "jquery",
       'jQuery': "jquery"
    })

In my entry-js I have:

import 'jquery';
import 'jquery-ui';
import 'jquery-slimscroll/jquery.slimscroll';
...
import angular from 'angular';
import 'angular-ui-router';
...

package.json:

"jquery": "~2.1.1",

For now I worked around it by manually importing jquery in the head of the entry html:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

来源:https://stackoverflow.com/questions/43706479/webpack-jquery-and-angular-jquery-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!