bower:jquery被声明为依赖,但不知何故失踪

时间:2013-11-21 23:23:12

标签: jquery gruntjs yeoman bower

我有一个带有这些依赖关系的bower.json:

"dependencies": {
    "bootstrap": "~3.0.2",
    "jquery": "~2.0.3",
    "modernizr": "~2.7.0"
  }

然后使用grunt构建生产文件。

Bower和Grunt使用yeoman和generator-webapp配置(之后我包括bootstrap3和更新的jquery和modernizr)。

该页面显示此错误:“未捕获错误:Bootstrap需要jQuery”

可能出现什么问题?

有没有办法确保在引导之前加载jquery?我已经尝试在bower.json中更改依赖项的顺序,但它没有帮助。

可能是在构建过程中没有包含jquery吗?我怎么会知道? (我是一个自耕农,凉亭和咕噜咕噜的小伙子)

这是我的index.html:

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="CH"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang="CH"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang="CH"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="CH"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>gabriel</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
        <!-- build:css(.tmp) styles/main.css -->
        <!-- bower:css -->
        <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
        <!-- endbower -->
        <!-- endbuild -->
        <!-- build:js scripts/vendor/modernizr.js -->
        <script src="bower_components/modernizr/modernizr.js"></script>
        <!-- endbuild -->
    </head>
    <body>
        <!--[if lt IE 10]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->


        <div class="hero-unit">
          <h1>'Allo, 'Allo!</h1>
          <p>You now have</p>
          <ul>
            <li>HTML5 Boilerplate</li>
            <li>Modernizr</li>
          </ul>
        </div>


        <!-- build:js scripts/vendor.js -->
        <!-- bower:js -->
        <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
        <!-- endbower -->
        <!-- endbuild -->

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='//www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X');ga('send','pageview');
        </script>

        <!-- build:js scripts/main.js -->
        <script src="scripts/main.js"></script>
        <!-- endbuild -->
</body>
</html>

1 个答案:

答案 0 :(得分:3)

使用bower获取库有两个步骤:

  1. 正在下载
    首先检查bower_components中是否存在jQuery 每当手动编辑bower.json时,您还必须运行bower update将库下载到bower_components
    如果您使用bower update引入新的依赖关系,则无需运行bower install

  2. 在您的应用代码中注明它们index.html
    Here's how to do it with grunt-bower-install。另一种可能性是使用RequireJS。

    如果bower在此步骤中遇到任何问题,请随意手动将<script ... </script>添加到index.html。通常当我添加新的依赖项时,在grunt bower-install的后续调用中,第一次调用会从index.html删除所有先前的依赖项,只留下新的依赖项,并且在它之后的调用会注入除新项之外的所有依赖项。