jQuery UI $(…).sortable is not a function with WebPack

后端 未结 3 1551
北恋
北恋 2021-01-04 10:58

I believe I\'ve set everything up correctly, but I\'m getting an odd issue with Webpack.

Consider this simple app.ts file:

\'use strict\         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 11:50

    The problem is that jQuery UI normally automatically pulls in the components it needs (which is why it works when it's linked via a CDN), but that doesn't work when it's imported as a module (like with Webpack).

    Thankfully as of jQuery UI 1.11 you can manually pull in any extra components you need like so:

    'use strict';
    
    import $ = require('jquery');
    
    require('jquery-ui');
    require('jquery-ui/ui/widgets/sortable');
    require('jquery-ui/ui/disable-selection');
    

    etc.

    Here's some official documentation explaining this further.

提交回复
热议问题