【问题标题】:Laravel/Vuejs app does not update after deploying to HerokuLaravel/Vuejs 应用程序在部署到 Heroku 后没有更新
【发布时间】:2020-03-23 21:07:53
【问题描述】:

我有一个在 localhost 上运行良好的 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'

【问题讨论】:

    标签: laravel vue.js heroku


    【解决方案1】:

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

    "heroku-postbuild": "npm run prod"
    

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

    【讨论】:

    • 非常感谢..这是缺少的部分!
    猜你喜欢
    • 2020-03-23
    • 2022-07-12
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 2015-05-09
    • 2019-02-06
    相关资源
    最近更新 更多