部署到Heroku后Laravel/Vuejs应用不会更新 [英] Laravel/Vuejs app does not update after deploying to Heroku

查看:68
本文介绍了部署到Heroku后Laravel/Vuejs应用不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Laravel/Vuejs app that works well on localhost. After deploying to Heroku, I realized that styles added to app.scss does not compile into my public/css file, thus have no effect. Also, modifications to my vuejs components does not update the app after I push to Heroku with git push heroku master.

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

I have added heroku/nodejs buildpack on my heroku dashboard. Here is my webpack.mix.js file content;

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文件:

My package.json file:

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

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

When i add a postinstall key to scripts like so:

"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'

推荐答案

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

Define a new script in your package.json:

"heroku-postbuild": "npm run prod"

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

This is how heroku executes the build script in the pipeline. It looks for build, otherwise you can customize it with heroku-postbuild.

这篇关于部署到Heroku后Laravel/Vuejs应用不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆