部署到Heroku后,Laravel / Vuejs应用不会更新

时间:2019-11-28 08:55:49

标签: laravel vue.js heroku

我有一个Laravel / Vuejs应用程序,在本地主机上运行良好。部署到Heroku之后,我意识到添加到app.scss的样式不会编译到我的public / css文件中,因此无效。另外,在我用git push heroku master推送到Heroku之后,对vuejs组件的修改不会更新应用程序。

我在heroku仪表板上添加了heroku / nodejs buildpack。这是我的webpack.mix.js文件内容;

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

mix.browserSync({
    proxy: 'localhost:8000'
});

我的package.json文件:

"scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "heroku-prebuild": "export NPM_CONFIG_PRODUCTION=false; export NODE_ENV=; NPM_CONFIG_PRODUCTION=false NODE_ENV=development npm install --only=dev --dev",
        "heroku-postbuild": "export NPM_CONFIG_PRODUCTION=true; export NODE_ENV=production"
    },

当我向类似这样的脚本中添加后安装密钥时:

"postinstall": "npm run prod"

我在部署时遇到错误:

remote:        npm ERR! errno 2
remote:        npm ERR! undefined postinstall: `npm run prod`
remote:        npm ERR! Exit status 2
remote:        npm ERR!
remote:        npm ERR! Failed at the undefined postinstall script.
remote:        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /tmp/npmcache.a6MDK/_logs/2019-11-28T08_41_39_044Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        Some possible problems:
remote:
remote:        - Node version not specified in package
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to blemademo.
remote:
To https://git.heroku.com/blemademo.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/blemademo.git'

1 个答案:

答案 0 :(得分:1)

在package.json中定义一个新脚本:

"heroku-postbuild": "npm run prod"

这是heroku在管道中执行构建脚本的方式。它会寻找build,否则,您可以使用heroku-postbuild对其进行自定义。