2016-03-11 105 views
2

我想將我的應用部署到heroku,但它拋出了我列在標題中的這個錯誤。我正在使用webpack將文件捆綁到文件中bundle.js我只是不確定如何將其部署到heroku,以便bundle.js可用。你如何協調webpack與heroku?我將附加我的db.js文件和package.json文件。在部署到heroku時出現錯誤「加載資源404錯誤」bundle.js

db.js

var Sequelize = require('sequelize'); 
var env = process.env.NODE_ENV || 'development'; 
var sequelize; 

if (env === 'production') { 
    sequelize = new Sequelize(process.env.DATABASE_URL, { 
     dialect: 'postgres' 
    }); // This if statement should execute if the app is run on Heroku 
} else { 
    sequelize = new Sequelize(undefined, undefined, undefined, { 
     'dialect': 'sqlite', 
     'storage': __dirname + '/data/practice-todo-api.sqlite' 
    }); 
} 



var db = {}; 

db.todo = sequelize.import(__dirname + '/models/todo.js'); 
db.user = sequelize.import(__dirname + '/models/user.js'); 
db.token = sequelize.import(__dirname + '/models/token.js'); 
db.sequelize = sequelize; 
db.Sequelize = Sequelize; 

db.todo.belongsTo(db.user); 
db.user.hasMany(db.todo); 

module.exports = db; 

的package.json

{ 
    "name": "practice-todo-api", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "start": "node server.js" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "axios": "^0.9.1", 
    "bcrypt": "^0.8.5", 
    "body-parser": "^1.13.3", 
    "crypto-js": "^3.1.5", 
    "express": "^4.13.3", 
    "jsonwebtoken": "^5.0.5", 
    "lodash": "^3.10.1", 
    "moment": "^2.11.2", 
    "pg": "^4.4.1", 
    "pg-hstore": "^2.3.2", 
    "react": "^0.14.7", 
    "react-dom": "^0.14.7", 
    "react-redux": "^4.0.0", 
    "react-router": "^2.0.0-rc5", 
    "redux": "^3.0.4", 
    "redux-form": "^4.1.3", 
    "redux-promise": "^0.5.1", 
    "request": "^2.60.0", 
    "sequelize": "^3.17.1", 
    "sqlite3": "^3.1.1", 
    "underscore": "^1.8.3" 
    }, 
    "devDependencies": { 
    "babel-core": "^6.5.1", 
    "babel-loader": "^6.2.2", 
    "babel-preset-es2015": "^6.5.0", 
    "babel-preset-react": "^6.5.0", 
    "babel-preset-stage-0": "^6.5.0", 
    "file-loader": "^0.8.5", 
    "webpack": "^1.12.13" 
    } 
} 
+0

是你的應用程序在l開發工作ocalhost? – s2t2

回答

2

Heroku的識別稱爲postinstall作爲部署生命週期,它運行後npm install執行的部分腳本。在postinstall腳本中,指定用於傳輸bundle.js文件的命令。

例如:

... 
"scripts": { 
    "build": "webpack --config ./config/webpack.config.js --progress --colors", 
    "start": "node server.js", 
    "postinstall": "npm run build" // referencing the "build" script above 
}, 
... 

一些有用的資源:

+1

這是非常有幫助的,我掙扎着很多這個問題是缺乏「後安裝」腳本transpailes的js:D 我的腳本: 「prepublish」:「npm我」, 「開始」: 「node index.js」, 「postinstall」:「./node_modules/.bin/webpack」 – MarioAraya