This answer is merely a summary of two helpfull other answers :
Answer 1, Answer 2
First, better to know that jquery-ui-dist
and jquery-ui-bundle
are not maintained by the jquery-ui team. So you will probably want to avoid using it. Nevertheless, from jquery-ui version 1.11 you can require/import AMD, and from version 1.12 you can use the official package with npm.
Solution 1 :
The preferred way to go is then to import part of jquery-ui such as :
import 'jquery-ui/ui/widgets/draggable';
The only drawback is that if you previously used import 'jquery-ui'
, you now have to import each modules you want to use specifically. But this is better as it will only bundle the imports you really need.
Check the 1.11 AMD support documentation and the 1.12 npm documentation on their site.
Solution 2 :
But, if for any reason you want to use a single global jquery-ui import, you will have to adapt your webpack config:
First, ensure webpack knows about the jquery aliases :
...
plugins: [
new webpack.ProvidePlugin({
'$':'jquery',
'jQuery':'jquery',
'window.jQuery':'jquery',
'global.jQuery': 'jquery'
}),
...
Then, help webpack resolving the jquery-ui js location :
resolve : {
alias: {
// bind version of jquery-ui
"jquery-ui": "jquery-ui/jquery-ui.js",
// bind to modules;
modules: path.join(__dirname, "node_modules"),
Then, ensure the jquery-ui is loaded as soon as possible (maybe during startup ?)
var $ = require("jquery"),
require("jquery-ui");
If you want to use a theme with jquery-ui, you will have to setup the css-loader and file-loader accordingly. (Don't forget to install those loaders):
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" },
{ test: /\.(jpe?g|png|gif)$/i, loader:"file" },
And below you imports of jquery and jquery-ui just add :
import 'modules/jquery-ui/themes/black-tie/jquery-ui.css';
import 'modules/jquery-ui/themes/black-tie/jquery-ui.theme.css';