2014-09-30 55 views
0

我使用的是自耕農webapp生成(0.5.0)和我的應用程序目錄的樣子:自耕農webapp的子文件夾錯誤的CSS路徑

app/ 
├── dir1 
│   └── index.html 
├── favicon.ico 
├── images 
├── index.html 
├── robots.txt 
├── scripts 
│   └── main.js 
└── styles 
    └── main.css 

dir1/index.html我剛剛複製的app/index.html的內容和修改後的道路的CSS和JS文件。 例如從

<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> 
<link rel="stylesheet" href="styles/main.css"> 

<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" /> 
<link rel="stylesheet" href="../styles/main.css"> 

使用grunt serve一切正常,但是當我用grunt build建立dir1/index.html的路徑是錯誤的。從Chrome開發者控制檯,我可以看到一些錯誤:

GET http://127.0.0.1/webapp/dir1/styles/9c307a9d.vendor.css  127.0.0.1/:1 
GET http://127.0.0.1/webapp/dir1/styles/84f823a4.main.css   127.0.0.1/:1 
GET http://127.0.0.1/webapp/dir1/scripts/db02b173.vendor.js   (index):3 
GET http://127.0.0.1/webapp/dir1/scripts/cb7562c6.plugins.js   (index):8 
GET http://127.0.0.1/webapp/dir1/scripts/b6c3df09.main.js    (index):8 

正確的路徑應該是:

http://127.0.0.1/webapp/styles/9c307a9d.vendor.css 
http://127.0.0.1/webapp/styles/84f823a4.main.css 
http://127.0.0.1/webapp/scripts/db02b173.vendor.js 
http://127.0.0.1/webapp/scripts/cb7562c6.plugins.js 
http://127.0.0.1/webapp/scripts/b6c3df09.main.js 

的問題是,一些繁重的任務使用dir1的根目錄,而不是父目錄。

我該如何解決這個問題?

回答

2

我已經找到了如何解決這個問題! 在dir1/index.html我不得不改變不僅外部文件的相對路徑(CSS,JS),而且也有咕嚕塊,例如代碼:

<!-- build:css(.) styles/vendor.css --> 
<!-- bower:css --> 
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> 
<!-- endbower --> 
<!-- endbuild --> 
<!-- build:css(.tmp) styles/main.css --> 
<link rel="stylesheet" href="styles/main.css"> 
<!-- endbuild --> 

應修改爲:

<!-- build:css(.) ../styles/vendor.css --> 
<!-- bower:css --> 
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" /> 
<!-- endbower --> 
<!-- endbuild --> 
<!-- build:css(.tmp) ../styles/main.css --> 
<link rel="stylesheet" href="../styles/main.css"> 
<!-- endbuild --> 
0

變化相對於網站,而不是相對路徑

<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css" /> 
<link rel="stylesheet" href="/styles/main.css"> 
+0

謝謝,但它不能解決我的問題。運行'grunt build'之後,路徑又變成了相對的 – Lorenzo 2014-10-01 17:20:10