问题
I have a repo that has the backend and frontend (create-react-app) in two separate folders. For the build command, I have something like cd frontend && npm run build
and for the publish directory, I have something like frontend/build
, but this is not working.
回答1:
disclaimer: I work for Netlify.
If you were to clone a new copy (no node modules installed in the project, for instance) of your project on a fresh laptop with nothing else except node and npm installed there, how would you build it? Imagine netlify's build process like that. So you're missing at least an "npm install" step in there :)
Anything else missing, like globally installed npm packages? Need to specify them in package.json
so that Netlify's build network knows to grab them for you. Ruby gems? Better have a Gemfile
in your repo!
Netlify tries to npm install
(and bundle install
) automatically for you, assuming there is a package.json
either in the root of your repository (I'm guessing yours is in frontend/
?) OR if you set the "base" parameter so that we start our build in the base directory. This is probably a good pattern for you, to set "base" to frontend
, and then set your publish directory to build
.
You can specify that base parameter in netlify.toml something like this:
[build]
base = "frontend"
Note that netlify.toml
must reside in the root of your repository.
For more details on how Netlify builds, check out the following articles:
- Overview of how our build network works. This article also shows how you can download our build image to test locally.
- Settings that affect our build environment. Useful for telling us about what node version to use, for instance.
- Some frequently experienced problems
If after some reading and experimenting, you still can't figure things out, ping the helpdesk.
来源:https://stackoverflow.com/questions/50364932/netlify-how-do-you-deploy-sites-that-are-nested-in-a-folder