I encourage you to NOT use my webpack.*.js files and rely on webpack init
for your front-end
because the files above have a lot of added plugins that are specific to the project I copied from.
That command will give you a working webpack.config.js for your local and production environment to
start with
At the very least, they can hopefully show you that you don't need to do anything particularly fancy in order to make this all work.
Your rails app is just a rails app. Your webpack app is just a webpack app. They are conjoined in development by nginx. No env vars or CORS config required.
You can run everything at once with: foreman start
.
nginx.conf
nginx/error.log
nginx/access.log
client/webpack.config
client/public/
api/Rakefile
Procfile
This comes down to where you are deploying to (AWS, Heroku, etc). All you need to understand is that
npm run build:production
produces a public/
folder. All files there are static and just need to be served to your users.
https://github.com/heroku/heroku-buildpack-static.git is great for this. Here is my static.json
file:
{
"root": "public/",
"canonical_host": "www.freedom.com",
"clean_urls": true,
"headers": {
"/": {
"Cache-Control": "no-store, no-cache"
},
"/**.xml": {
"Content-Type": "application/xml"
}
},
"https_only": true,
"proxies": {
"/api/": {
"origin": "https://${API_APP_NAME}.herokuapp.com/api/"
}
}
}
Again, it uses nginx under the hood so no special CORS configuration needed! API_APP_NAME
is just a bash environment variable.
It should point to where you are hosting your rails API, whether that's in another heroku app like above, or a different url.