Created
December 8, 2020 19:43
-
-
Save henrypoydar/e89e38fa81211aca67db8788b5ebaa17 to your computer and use it in GitHub Desktop.
Use webpack-dev server to hot reload Rails views when they change in development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.env.NODE_ENV = process.env.NODE_ENV || "development"; | |
const environment = require("./environment"); | |
// Hot reload views via webpack dev server. | |
// https://github.com/rails/webpacker/issues/1879 | |
// However, Circle CI system test choke on this. NODE_ENV is | |
// 'development' in tests by default. So check RAILS_ENV and | |
// skip hot reload in testing. | |
if (process.env.RAILS_ENV == "development") { | |
const chokidar = require("chokidar"); | |
environment.config.devServer.before = (app, server) => { | |
chokidar | |
.watch([ | |
"config/locales/*.yml", | |
"app/views/**/*.md", | |
"app/views/**/*.html.erb", | |
"app/views/**/*.html.haml", | |
]) | |
.on("change", () => server.sockWrite(server.sockets, "content-changed")); | |
}; | |
} | |
module.exports = environment.toWebpackConfig(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment