加载了 JqueryUI 的 Browserify 无法正常工作

Browserify loaded with JqueryUI not working

我在使用 Browserify 加载 Jquery-UI 时遇到问题。

jquery 和 jquery-ui 的节点模块加载正常,没有任何问题。只有当我尝试使用 browserify 将它们请求 ui 重新打包并加载 JqueryUI 日期选择器时,我在浏览器中收到以下 javascript 错误:

jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function

app.js 包含以下内容:

window.$ = window.jQuery = require('jquery');
require('jquery-ui');

我也在使用 gulp 和 laravel-elixer,我的 package.json 包含:

{
   "private": true,
   "scripts": {
     "production": "gulp --production",
     "dev": "gulp watch",
   },
   "dependencies": {
     "gulp": "^3.9.1",
     "jquery": "^3.1.0",
     "jquery-ui": "^1.12.0",
     "laravel-elixir": "^5.0.0"
   }
}

gulpfile.js 包含:

var elixir = require('laravel-elixir');
elixir(function (mix) {
    mix.sass('app.scss');
    mix.browserify('app.js');
    mix.version(['css/app.css', 'js/app.js']);
});

这是一个错误还是我做错了什么?谢谢

可能您正在使用 jQuery-UI 1.12。 Browserify 与新版本不兼容。 官方升级页面说:

If you're using browserify: The UMD headers we have aren't supported by browserify natively, and the deamdify plugin has a blocking bug. If you depend on that combination, please help fix that bug!

https://jqueryui.com/upgrade-guide/1.12/

我自己还没有尝试过,但您可以通过要求单独的小部件来实现它

var autocomplete = require( "jquery-ui/ui/widgets/autocomplete" );