# Rails 6 + Vue.js 2 Starter Kit GitHub Template. **NOTE:** For Rails 5.2, please check https://github.com/jetthoughts/vuejs-rails-starterkit/tree/rails-5-latest [](https://heroku.com/deploy)  [](https://circleci.com/gh/jetthoughts/vuejs-rails-starterkit) [](https://codecov.io/gh/jetthoughts/vuejs-rails-starterkit) A quick and easy way to setup Rails + PWA + Turbolinks + Webpacker + Bootstrap with AdminLTE theme + Vue + Jest. If your team is considering or has already decided to use Vue, this is the right for you. As an additional review of how to setup PWA, Turbolinks, CSS frameworks, Storybook. ### Preview of all steps [](https://asciinema.org/a/ArqvGrc6JK6pKzlRTMV3Jotwr) ### Expected Final Screen  ## Table of Contents - [Step 1. Generate Ruby on Rails Project with Vue.js](#generate-ruby-on-rails-project-with-vuejs-no-turbolinks-included-on-this-stage) - [Step 2. Setup development environment](#setup-development-environment) - [Step 3. Add sample page to host Vue.js component](#add-sample-page-to-host-vuejs-component) - [Step 4. Use Webpacker assets in the application](#use-webpacker-assets-in-the-application) - [Step 5. Install Jest for Component Unit Tests](#install-jest-for-component-unit-tests) - [Step 6. Setup Heroku and Deploy](#setup-heroku-and-deploy) - [Step 7. Setup basic PWA](#setup-basic-pwa) - [Step 8. Setup Turbolinks](#setup-turbolinks) - [Step 9. Installs UI Kit - AdminLTE](#setup-adminlte) - [Step 10. Configure continuous integration and other services for static code analysis](#configure-continuous-integration-and-other-services-for-static-code-analysis) #### Things you may want to cover: #### Features: * Optimized for peformance Webpacker with Vue.js: Lazy Load, Split Chunks * Turbolinks * PWA * Backend Unit and System Tests with coverage * Vue.js Unit Tests with coverage * Deployable to Heroku * Pre-setup for services: - GitHub - Heroku (Heroku Reviews Apps) - CircleCI - Codecov and Simplecov - Dependabot * Static Code Analyzers: - Pronto - Rubocop - ESLint - EditorConfig #### Dependencies: * [Ruby on Rails](https://rubyonrails.org/) version 6 * [Vue.js](https://vuejs.org) version 2 with [Vue Test Utils](https://vue-test-utils.vuejs.org/) * [Webpacker](https://github.com/rails/webpacker) 5 with [Webpack](https://webpack.js.org/) 4 * [Bootstrap](https://getbootstrap.com/) 4 with [AdminLTE Template](https://adminlte.io/) * [Babel](https://babeljs.io/) 7 #### System Dependencies: * [Ruby](https://www.ruby-lang.org/en/) 3.0 * [Node.js](https://nodejs.org/en/) 14 * [Yarn](https://yarnpkg.com/en/) * [PostgreSQL](https://www.postgresql.org/) 12 * [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) ## Generate Ruby on Rails Project with Vue.js (No Turbolinks included on this stage) ```bash gem install rails rails new vuejs-rails-starterkit --force --database=postgresql \ --skip-action-mailer --skip-action-cable --skip-sprockets --skip-turbolinks \ --webpack=vue cd ./vuejs-rails-starterkit bin/rails db:create db:migrate ``` This generates Rails project with: - Vue component in `app/javascript/app.vue` - Example entry file `app/javascript/packs/hello_vue.js` ### Setup development environment: 1. Uncomment `system('bin/yarn')` in `bin/setup` and `bin/update` to install new node modules. 2. Install dependencies: ```bash bin/setup ``` 3. Enable *content_security_policy* in the `config/initializers/content_security_policy.rb` with the following configuration: ```ruby Rails.application.config.content_security_policy do |policy| policy.script_src :self, :https if Rails.env.development? || Rails.env.test? policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' end end ``` 4. Verify that we have not broken anything ```bash bin/webpack bin/rails runner "exit" ``` ### Add sample page to host Vue.js component 1. Generate controller and view: ```bash bin/rails generate controller Landing index --no-javascripts --no-stylesheets --no-helper --no-assets --no-fixture ``` 2. Update `app/views/landing/index.html.erb` to: ```erb
Find me in app/views/landing/index.html.erb
``` 3. Change `app/javascript/packs/hello_vue.js` to: ```javascript import Vue from 'vue' import App from '../app.vue' document.addEventListener('DOMContentLoaded', () => { const app = new Vue({ render: h => h(App), el: '#hello_vue_app' }).$mount() }) ``` 4. Setup a sample page as a home page by updating `config/routes.rb`: ```ruby root 'landing#index' ``` ### Use Webpacker assets in the application 1. Enable Webpacker with `SplitChunks`: * Enable `SplitChunks` with default config by adding to `config/webpack/environment.js`: ```js environment.splitChunks() ``` * Enable Webpacker by updating `app/views/layouts/application.html.erb`: Change: ```erb <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_pack_tag 'application' %> ``` to: ```erb <%= stylesheet_packs_with_chunks_tag 'application', 'hello_vue', media: 'all' %> <%= javascript_packs_with_chunks_tag 'application', 'hello_vue' %> ``` 2. Verify locally that vue.js is working and `SplitChunks` is enabled ```bash bin/rails s open "http://localhost:3000/" ``` Expect to see  The `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers split assets into small size chunks and create html tags for them: ```html ``` ## Install Jest for Component Unit Tests 1. Add Jest with required dependencies ```bash yarn add --dev jest @vue/test-utils vue-jest babel-core@^7.0.0-bridge.0 babel-jest jest-serializer-vue ``` 2. Configure Jest in `package.json` (including the Coverage enabling): ```json "scripts": { "test": "jest" }, "jest": { "verbose": true, "testURL": "http://localhost/", "roots": [ "test/javascript" ], "moduleDirectories": [ "node_modules", "app/javascript" ], "moduleNameMapper": { "^@/(.*)$": "