This buildpack allows you to deploy a subdirectory of your Git repository as a Heroku app, with enhanced support for monorepo projects that share common dependencies.
Add as the first buildpack in the chain. Set the PROJECT_PATH environment variable to point to your project root. It will be promoted to the slug's root along with any shared dependencies, then the following buildpack (e.g. Node.js) will finish slug compilation.
Disclaimer: This is a fork with monorepo enhancements. Always pin to a specific GitHub version. Provided as is.
- Subdirectory deployment: Deploy only a specific subdirectory of your repository
- Monorepo support: Automatically preserves shared dependencies (like a
common/directory) - Clean structure: Maintains relative paths so no code changes are needed
- Wrapper package.json: Creates a root-level package.json that delegates to your project
-
Clear existing buildpacks (if necessary):
heroku buildpacks:clear
-
Add this buildpack (replace with your fork URL):
heroku buildpacks:add https://github.com/YOUR_USERNAME/subdir-heroku-buildpack
-
Add your language buildpack:
heroku buildpacks:add heroku/nodejs
Or whatever buildpack you need for your application.
-
Configure PROJECT_PATH:
heroku config:set PROJECT_PATH=api
Point to the subdirectory you want to deploy.
-
Deploy:
git push heroku master
If you only have a PROJECT_PATH configured, the buildpack:
- Copies your subdirectory contents to a temporary location
- Erases everything else
- Moves the subdirectory contents to the project root
- Normal Heroku slug compilation proceeds
If your repository has both a PROJECT_PATH and a common/ directory at the root, the buildpack:
- Preserves the directory structure by keeping both directories
- Creates a root
package.jsonwrapper that:- Installs dependencies in your project directory
- Installs extension/subdirectory dependencies if needed
- Delegates
startandheroku-postbuildcommands to your project
- Maintains all relative paths, so imports like
../../../commoncontinue to work
Before buildpack:
your-repo/
api/
package.json
extensions/
some-extension/
common/ ← Shared types, utilities, etc.
front/
infra/
After buildpack (BUILD_DIR):
BUILD_DIR/
package.json ← Wrapper created by buildpack
api/
package.json ← Your original
extensions/
some-extension/
common/ ← Preserved!
PROJECT_PATH: Path to your project subdirectory (e.g.,api,backend,server)
- Place a
common/directory at the repository root to share code between projects - The buildpack will automatically detect and preserve it
Perfect for:
- Monorepo projects with shared TypeScript types/utilities
- Projects with multiple apps (frontend, backend, etc.) where you deploy each separately
- Clean separation of concerns while maintaining code reuse
This is a fork of timanovsky/subdir-heroku-buildpack with added monorepo support.