我正在向Heroku部署Angular应用程序,我需要bower来添加Angular组件和其他一些组件。部署正在运行,除部署的站点之外的所有内容都缺少bower_components文件夹。我已经浏览了所有内容,并阅读了许多StackOverflow帖子,但我必须遗漏一些东西。这是我的代码:
package.json
{
"name": "my-webapp",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"bower": "^1.8.0",
"express": "^4.15.2"
},
"devDependencies": {},
"scripts": {
"start": "node web.js",
"postinstall": "./node_modules/bower/bin/bower install"
},
"repository": {
"type": "git",
"url": "git+https://github.com...."
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com..."
},
"homepage": "https://github.com...",
"description": ""
}
web.js
var express = require('express'),
app = express();
app.use(express.static(__dirname));
app.get('/', function(req, res) {
res.sendfile('index.html', {root: __dirname })
});
var server = app.listen(process.env.PORT || 80);
Procfile
web: node web.js
bower.json
{
"name": "my-webapp",
"description": "",
"main": "app.js",
"authors": [
"Me"
],
"license": "ISC",
"homepage": "https://my-webapp.herokuapp.com/",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular-material-icons": "^0.7.1",
"angular-material": "^1.1.1",
"materialize": "^0.97.8",
"ng-lodash": "^0.5.0"
}
这是构建输出,编辑的亮点:
-----> Building dependencies
Prebuild detected (node_modules already exists)
Rebuilding any native modules
bower@1.8.0 /tmp/build_9a163093ad395af381c984026f6a5742/me-my-webapp-bfae0f9/node_modules/bower
express@4.15.2 /tmp/build_9a163093ad395af381c984026f6a5742/mugwag-my-webapp-bfae0f9/node_modules/express
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components
-----> Build succeeded!
-----> Rebuilding any native dependencies
bower@1.8.0 /tmp/build_9a163093ad395af381c984026f6a5742/me-my-webapp-bfae0f9/node_modules/bower
express@4.15.2 /tmp/build_9a163093ad395af381c984026f6a5742/me-my-webapp-bfae0f9/node_modules/express
????????? bower@1.8.0
npm WARN my-webapp@1.0.0 No description
-----> Found bower.json, running bower install
-----> Installing dependencies
> my-webapp@1.0.0 postinstall /tmp/build_9a163093ad395af381c984026f6a5742/me-my-webapp-bfae0f9
> ./node_modules/bower/bin/bower install
npm WARN my-webapp@1.0.0 No description
对我来说,看起来好像一切正常,但是当我加载页面时,我得到一堆破坏了bower_components文件夹的链接:
无法获取/bower_components/materialize/dist/css/materialize.css
没有凉亭文件夹。为什么!?
答案 0 :(得分:0)
仅供参考 - 我从未解决过这个问题,但现在使用Amazon S3来托管Angular应用程序。因为Angular完全是客户端,所以不需要服务器。只需将代码上传到S3或类似的,普通主机并直接引用它。
我希望能有所帮助。