I'm building a Single Page (Web) Application. I'm quite smitten by Rails v5.0, especially its built-in API capabilities.
In the past I've built JavaScript frontends using Vue.js
, usually with the templates provided by the Vue-CLI project
. This allows deployment of Vue component-based
static sites basically anywhere. It's great.
Now, Rails 5.1
has some built-in Webpack and Yarn features which look pretty compelling too. I'm not sure how to proceed with my new application.
My questions:
- What are the pros/cons of integrating Webpack and Vue into Rails itself, using the Webpacker extensions available in Rails v5.1? I intend to deploy to Heroku.
- On the other hand, what are the pros/cons of using the Rails API-only mode for the backend, and maintaning the Vue/Webpack-based frontend in its own directory? I'd keep everything in the same repository, deploy the backend via Heroku, and the frontend via a static host like Netlify.
- Which approach would have more cognitive overhead or technical complexity?
Over the past few days, I've been looking around, and I've not found much concise information on the web about this. People seem interested in the auto-reloading features of the Rails development environment, but I get that for free already with Vue-CLI.
As far as I can discern, these are reasons for keeping them separate:
- Deployment of the frontend is pretty darn simple to anywhere.
- The Webpacker mode for Rails is very new, and not many tutorials or guides exist yet, especially regarding integration testing. Keeping things separate means that my existing testing apparatus should still apply.
Here are some pros for integrating the two parts together:
- The possibility of using static assets both for the frontend and possibly for server-generated pages in the future, should that be necessary.
- Buy-in to "the Rails way", with implied future maintenance by the Rails team.
- the JS Frontend would not need to be hosted separately.
- Don't need to worry about CORS (?)
What other concrete benefits exist for either approach?
dist
folder, but you can certainly point Webpack to the Railspublic
folder instead. I left this out of the question because I was concerned it would muddy the waters. Thanks – Katheryn