2013-11-21 39 views
3

我有這些依賴關係的bower.json:涼亭:jQuery是聲明的依賴,但不知何故失蹤

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

生產文件,然後使用咕嚕建。

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

頁顯示了這個錯誤:「未捕獲錯誤:引導需要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> 
+0

腳本加載後,檢查jQuery是否存在。那麼你至少可以把問題縮小到訂單問題。 – Brad

+0

我在「dist」文件夾中找不到jquery的任何痕跡,其中產品代碼由grunt構建插入。它在index.html中的html中也沒有出現。 – Alex

+0

我添加了我的index.html文件。也許這就是應該改變的地方? – Alex

回答

3

有獲得與涼亭庫2步:

  1. 他們下載
    首先檢查jQuery是否存在於bower_components
    無論何時手動編輯bower.json,您還必須運行bower update將庫下載到bower_components
    如果您引入了bower install的新依賴項,則不需要運行bower update

  2. 注入他們在您的應用程序代碼(index.html
    Here's how to do it with grunt-bower-install。另一種可能是使用RequireJS。

    如果涼亭在這一步中有任何問題,請隨時將您需要的<script ... </script>手動添加到index.html。通常當我添加一個新的依賴關係時,在grunt bower-install的後續調用中,首次調用會從index.html中刪除所有先前的依賴關係,並且只留下新的依賴項,並且其後的調用會注入除新的依賴項之外的所有依賴項。

+1

是的。我曾看過你鏈接的文章,但錯過了「咕嚕涼亭安裝」。那做了這個工作。非常感謝! – Alex