Deploying Yeoman apps to Heroku
卡在 deploy 好幾天了
今天終於成功
要把步驟記下來...
首先準備好 yeoman app
接著在 /yeoman-app 下
$ grunt build
這時候出現了
Warning: Running "imagemin:dist" (imagemin) task
Fatal error: Cannot read property 'contents' of undefined
參考此篇 Fatal error: Cannot read property 'contents' of undefined #330
$ rm -rf node_modules
modify "grunt-contrib-imagemin": "1.0.0" in package.json
$ npm install
再重跑一次後接著下一步
$ cd dist && npm init
$ npm install express gzippo --save
新增一個 index.js, 裡頭內容如下:
'use strict';
var express = require('express');
var http = require('http');
var gzippo = require('gzippo');
var app = express();
app.use(gzippo.staticGzip('' + __dirname));
app.use('/*', function(req, res){
res.sendfile(__dirname + '/index.html');
});
var server = http.createServer(app);
server.listen(process.env.PORT || 5000);
再新增一個 Procfile, 裡頭內容如下:
web: node index.js
新增一個 .gitignore, 裡頭內容如下:
# Ignore pattern for Production
node_modules
開 Heroku app 後 commit new repo
$ heroku create <app-name>
$ git init
$ heroku git:remote -a <app-name>
$ git add .
$ git commit -am "Initial commit"
$ git push heroku master
最後打開
$ heroku ps:scale web=1
$ heroku open
0 comments:
張貼留言