问题
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