Masatoshi Nishiguchi

Rails - what to do after installing webpacker

This is my note on how to use webpacker after installation.

dependencies

set up files

app/views/layouts

/ app/views/layouts/application.slim

doctype html
html
  head
    title = full_title yield(:title)
    = csrf_meta_tags
    = csp_meta_tag
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'
    = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'

    = javascript_pack_tag 'application'
    = stylesheet_pack_tag 'application'
    /...

app/javascript/packs

// app/javascript/packs/application.js

// import js
import './javascript';

// import css
import './stylesheet';

// senity check
console.log('Hello World from Webpacker');
// app/javascript/packs/stylesheet/index.js

// any js here
// app/javascript/packs/stylesheet/index.scss

// any scss here

start app

# run webback server
bin/webpack-dev-server
# run rails server
bin/rails s