部署到heroku时出错“faliled to load resource 404”bundle.js

时间:2016-03-11 11:56:41

标签: node.js postgresql heroku webpack

我正在尝试将我的应用程序部署到heroku,但它正在抛出我在标题中列出的错误。我正在使用webpack将文件捆绑到文件中 bundle.js 我只是不确定如何将其部署到heroku以便bundle.js可用。你如何调和webpack与heroku?我将附加我的db.js文件和package.json文件。

db.js

List<string>.Enumerator

的package.json

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;

1 个答案:

答案 0 :(得分:4)

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
},
...

一些有用的资源: