如何使Heroku运行Flask应用程序的Webpack?

时间:2019-02-23 22:53:13

标签: heroku flask webpack vuejs2 gunicorn

我正在尝试将我的测试Flask应用程序部署到Heroku。除前端外,其他所有东西都在工作。我使用由webpack构建的Vuejs。

我的个人档案:

web: npm install; npm run dev; gunicorn app:app

我的package.json:

{
    "name": "test",
    "version": "1.0.0",
    "description": "",
    "scripts": {
        "build": "webpack --config webpack.dev.js",
        "heroku-postbuild": "webpack --config webpack.dev.js"
    },
    "keywords": [],
    "author": "",
    "devDependencies": {
        "clean-webpack-plugin": "^0.1.19",
        "css-loader": "^1.0.0",
        "html-loader": "^0.5.5",
        "node-sass": "^4.9.3",
        "sass-loader": "^7.1.0",
        "style-loader": "^0.23.0",
        "vue-loader": "^15.4.2",
        "vue-template-compiler": "^2.5.17",
        "webpack": "^4.19.0",
        "webpack-cli": "^3.1.0",
        "webpack-merge": "^4.1.4"
    },
    "dependencies": {
        "@fortawesome/fontawesome-free": "^5.3.1",
        "axios": "^0.18.0",
        "bootstrap": "^4.1.3",
        "file-loader": "^2.0.0",
        "jquery": "^3.3.1",
        "jquery.easing": "^1.4.1",
        "lodash": "^4.17.11",
        "moment": "^2.22.2",
        "popper.js": "^1.14.4",
        "vue": "^2.5.17",
        "vue-router": "^3.0.1",
        "vuex": "^3.0.1",
        "webpack": "^4.19.0"
    }
}

输出完全不表明它运行了webpack:

$ git push heroku master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 322 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 33.5M
remote: -----> Launching...
remote:        Released v13
remote:        https://mytestapp.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/mytestapp.git
   1fdf467..33852e6  master -> master

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决此问题的方法。

它被称为“多个buildpacks”,并在此处进行了描述:https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app

因此,如果您需要更多的“编译器”,则需要手动添加它们。就我而言,我已经认识了Python,但是没有Node.js。因此,首先我运行以下命令:

heroku buildpacks:add --index 1 heroku/nodejs

然后,当我运行

heroku buildpacks

我看到了:

  1. heroku/nodejs
  2. heroku/python

然后更改了package.json:

"scripts": {
    "heroku-prebuild": "npm install",
    "heroku-postbuild": "webpack --config webpack.dev.js"
}

并推送到heroku。