DEV Community

Cover image for Webpacker 6: Tutorial Setup
Andrew Mason
Andrew Mason

Posted on • Edited on • Originally published at andrewm.codes

Webpacker 6: Tutorial Setup

Before we start the upgrade process for Webpacker 6, we are going to create a small demo application for us to work on.

If you are upgrading an existing app or not using this series as a tutorial, you can skip this step! We will begin the formal upgrade process in the next article.

Generate a new Rails app

First we will generate new Ruby on Rails app:

rails new webpacker_6 --skip-sprockets --skip-spring --skip-webpack-install --skip-bundle cd webpacker_6 
Enter fullscreen mode Exit fullscreen mode
  • --skip-sprockets: Skip Sprockets files
  • --skip-spring: Don't install Spring application preloader
  • --skip-bundle: Don't run bundle install
  • --skip-webpack-install: Don't run Webpack install

Setup the Database

bin/rails db:prepare 
Enter fullscreen mode Exit fullscreen mode

Turn off asset scaffolding

Prevent Rails from creating asset files when running the generators and scaffolds:

# config/application.rb # ... module Webpacker6  class Application < Rails::Application config.load_defaults 6.1 + config.generators do |g| + g.assets false + end  end end 
Enter fullscreen mode Exit fullscreen mode

Add Pages Controller

Generate pages controller with a home action:

bin/rails g controller pages home 
Enter fullscreen mode Exit fullscreen mode

Add Root Route

Set pages#home as the root route:

# config/routes.rb Rails.application.routes.draw do get 'pages/home' + root to: 'pages#home'  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end 
Enter fullscreen mode Exit fullscreen mode

Note: Because we skipped the Webpacker install task, you will get an error if you try to start the application as is. We will fix that in the next article.

Top comments (1)

Collapse
 
juanvqz profile image
Juan Vasquez

Hi!
why did you remove sprockets?
why is used for?

--skip-sprockets: Skip Sprockets files 
Enter fullscreen mode Exit fullscreen mode