Laravel/Vuejs 应用程序在部署到 Heroku 后不会更新

ban*_*nky 3 heroku laravel vue.js

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

我已经在我的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'
});
Run Code Online (Sandbox Code Playgroud)

我的 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"
    },
Run Code Online (Sandbox Code Playgroud)

当我向脚本添加安装后密钥时,如下所示:

"postinstall": "npm run prod"
Run Code Online (Sandbox Code Playgroud)

我在部署时遇到错误:

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'
Run Code Online (Sandbox Code Playgroud)

Ohg*_*why 5

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

"heroku-postbuild": "npm run prod"
Run Code Online (Sandbox Code Playgroud)

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