【发布时间】:2014-03-16 07:37:30
【问题描述】:
我有一个目录结构
projectName
| - bower_components/
| - public/
| - css
| - js
| - index.html
| - Gruntfile.js
| - package.json
| - bower.json
| - app.js
我想启动我的应用程序并使用节点服务index.html。所以在app.js 我有:
var express = require('express');
var port = process.env.PORT || 3000;
var app = express();
app.configure(function(){
// Serve up content from public directory
app.use(express.static(__dirname + '/public'));
app.use(app.router);
app.use(express.logger());
});
app.listen(port, function(){
console.log('Express server listening on port ' + port);
});
在index.html的底部我有:
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/d3/d3.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/spin.js/spin.js"></script>
<script src="bower_components/mustache/mustache.js"></script>
当我启动服务器时,index.html 出现了,但是上面的库都没有加载。我收到错误(404):
GET http://localhost:3000/bower_components/jquery/jquery.js 404 (Not Found) localhost/:32
GET http://localhost:3000/bower_components/d3/d3.js 404 (Not Found) localhost/:33
GET http://localhost:3000/bower_components/bootstrap/dist/js/bootstrap.js 404 (Not Found) localhost/:34
GET http://localhost:3000/bower_components/spin.js/spin.js 404 (Not Found) localhost/:35
GET http://localhost:3000/bower_components/mustache/mustache.js 404 (Not Found)
如何从 bower_components 提供文件?
【问题讨论】:
-
另请参阅我的类似问题(已回答),也许它可能会有所帮助:stackoverflow.com/questions/23933621/…
-
我有一个问题。
package.json和bower.json是否相互冲突?对于名称,版本等字段,甚至可能具有不同版本的相同包的依赖项。你在 package.json 中放了什么,在 bower.json 中放了什么? -
package.json用于 npm 依赖项(很多时候是服务器端或构建系统要求),其中bower.json仅用于客户端依赖项,如引导、角度或 jquery。它们不会相互冲突
标签: javascript node.js express bower