Live Reload

LiveReload with Webpack for views and viewcomponents..
Icons/chart bar
Used 69 times
Created by
R Roland Studer

Usage
Start your webpack-dev-server with

./bin/webpack-dev-server

All changes in `app/views` and `app/components` will trigger a page reload.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/V1bs61"
Template Source

Review the code before running this template on your machine.

file = 'config/webpack/development.js'

inject_into_file file, before: "process.env.NODE_ENV = process.env.NODE_ENV || 'development'\n" do <<~EOF
  var path = require('path')

  EOF
end

inject_into_file file, after: "const environment = require('./environment')\n" do <<~EOF
  
  environment.config.devServer.watchContentBase = true
  environment.config.devServer.contentBase = [
    path.join(__dirname, '../../app/views'),
    path.join(__dirname, '../../app/components')
  ]

  EOF
end
Comments

Sign up or Login to leave a comment.