-->

如何使用jQuery用户界面与亭子?(How to use jquery ui with bower

2019-09-01 09:28发布

我与实验自由民和亭子 。

我曾尝试使用下面的命令创建一个web应用自耕农

yo webapp

我想使用jQueryUI的 ,所以我也用它鲍尔安装:

bower install jquery-ui --save

这工作得很好,但jQuery UI的部分不包含“所有”的组件的JavaScript文件,它只是包含了大量的JavaScript文件,每一个组件。

我应该只包含我需要的JavaScript文件? 或者我应该做使用jQuery UI之前别的东西吗?

感谢您的提示!

Answer 1:

新增jquery-uidependenciesbower.json (或component.json沿) jquery

{
  …,
  "dependencies": {
    "jquery": "~1.9.1",
    "jquery-ui": "~1.10.3",
    ...
  },
  …
}

安装:

bower install

然后,添加路径jqueryuimain.js并要求其:

require.config({
  paths: {
    jquery: '../components/jquery/jquery',
    jqueryui: '../components/jquery-ui/ui/jquery-ui',
    …
  },
  shim: {
    jqueryui: 'jquery',
    …
  },
  …
});
require(['app', 'jquery', 'jqueryui', 'bootstrap'], function (app, $) {
  'use strict';
   ...
});

这个对我有用。



Answer 2:

(诉1.10.3)在最新的jQuery UI的亭子组成,因为我们说话,你可以做到以下几点:

  1. 对于CSS主题,包括以下链接:

    <link rel="stylesheet" href="bower_components_path/jquery-ui/themes/base/jquery-ui.css">

  2. 为了获得最大的组件和jQueryUI的运行窗口小部件,包括下面的脚本:

    <script src="bower_components_path/jquery-ui/ui/jquery-ui.js" ></script>



Answer 3:

作为参考, bower install jquery-ui --save将添加jquery-ui.js依赖的项目,而不是风格。 对于我需要添加到bower.json文件的overrides部分,如下

{
  ...,
  "dependencies": {
    ...,
    "jquery-ui": "^1.11.4" // already added with --save from bower install command
  },
  ...,
  "overrides": {
    "jquery-ui": {
      "main": [
        "themes/smoothness/jquery-ui.css",
        "jquery-ui.js"
      ]
    }
  }
}

参考文献:

https://stackoverflow.com/a/27419553/4126114

https://github.com/taptapship/wiredep/issues/86



Answer 4:

我只想包括我需要或使用默认的自定义生成的文件夹(我相信这所有的组件),如果你需要的一切,或者如果它只是用于实验的文件。

<script src="components/jqueryui/ui/jquery-ui.custom.js"></script>

这时凉亭拉低整个回购,因为(从他们的网站)“鲍尔只是一个包管理器”什么都需要像串联或加载模块是由像链轮/ requirejs其他工具处理。

参考文献:

使用封装,在主页上凉亭http://bower.io/

约亭子Dissusion和拉动整个回购https://github.com/bower/bower/issues/45



Answer 5:

你可以使用requirejs.config的垫片属性来实现自己的目标:

requirejs.config({
    shim: {
        'jquery.ui.sortable': {
            deps: ['jquery', 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.mouse', 'jquery.ui.position'],
            exports: '$'
        }
    }
});

我们规定,即jquery.ui.sortable,需要在你的项目时,需要加载并执行下面列出的模块deps执行本身之前先。

不幸的是,这仍然会产生竞态条件......但是,这通常是一个将如何去这个(:



文章来源: How to use jquery ui with bower?