Heroku deploy a sub directory?

前端 未结 3 1694
夕颜
夕颜 2021-02-05 08:38

I\'m trying to deploy a node app, but I\'m running into a problem with how my code is structure. The app is git inited at the top level and it looks like:

App (         


        
相关标签:
3条回答
  • 2021-02-05 09:23

    I think git-subtree should work:

    git subtree push --prefix server heroku master

    Additional resources:

    • How can I deploy/push only a subdirectory of my git repo to Heroku?
    • https://coderwall.com/p/ssxp5q
    0 讨论(0)
  • 2021-02-05 09:28

    Heroku requires a package.json and a lockfile in the root of the repository or they will fail the deploy.

    However you can set up a package.json in the root of the repo which installs dependencies for the subdirectories and runs their related commands.

    Using yarn for example, in your case you could put an empty yarn.lock in the root and a package.json like:

    {
      "name": "my-project",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "postinstall": "yarn --cwd server --production=false install",
        "build": "yarn --cwd server serve"
      }
    }
    

    The --production=false ensures that devDependencies will be installed, which otherwise wouldn't happen since NODE_ENV is set to production in Heroku's environment.

    0 讨论(0)
  • 2021-02-05 09:30

    Alternatively, you can use git subtree to create a heroku branch on GitHub:

    git subtree push --prefix server origin heroku
    

    which you can then deploy to Heroku using a Heroku Button. Just add an app.json and a README.md with the button to your server directory:

    [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
    

    Deploy

    and let Heroku take care of the rest.

    0 讨论(0)
提交回复
热议问题