These snippets show how to enable polling for filesystem changes when using
nodemon
for Node apps (ExpressJS, etc)rails server
webpack-dev-server --watch
ember server
You can probably look at these examples and Google to find similar solutions for other dev servers.
Development servers, transpilers and other build tools often provide a watch command, to watch for source file changes and recompile/reload automatically.
Programs running in a Vagrant VM usually can't detect file changes when a file is saved on the host OS (e.g. most editors). So you need to switch to polling (periodically checking for changes) instead.
(Compared to filesystem events, polling is slower to respond to changes and much more I/O-intensive, so it's not often enabled by default. Also, the issue actually belongs more specifically to VirtualBox and the way it does shared directories. Running Vagrant atop something like VMware may just work.)
nodemon is a tool for running NodeJS apps and automatically reloading whenever certain files change.
It seems nodemon can be used normally with varying success in Vagrant long bug thread here. If it doesn't reload properly:
- Try using the
-L
flag (nodemon -L app.js
)
If performance suffers or it takes too long to reload:
- Try watching only specific directories (
nodemon -L --watch src --watch lib
) - and/or, try ignoring filename patterns you don't want to watch (
nodemon -L --ignore 'dist/*.js'
). nodemon should already ignore things likenode_modules/*
by default.
https://stackoverflow.com/questions/35959490/rails-server-doesnt-see-code-changes-and-reload-files
In config/environments/development.rb
:
# uses filesystem events:
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# uses polling:
config.file_watcher = ActiveSupport::FileUpdateChecker
FileUpdateChecker
will use polling.
Need to add these watch options to enable polling:
{
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/
}
Programmatically:
# server.js
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/
}
})
.listen(3000, '0.0.0.0', function (err, result) {
if (err) {
console.log(err);
}
console.log('Running at http://0.0.0.0:3000');
});
Or command-line:
node_modules/.bin/webpack-dev-server --host 0.0.0.0 --watch --watch-aggregate-timeout 300 --watch-poll 1000
Note: Not sure if --watch-ignore
is a thing or if it works, or how to ignore a filename pattern on the command-line. But ignoring the regex pattern /node_modules/
improves performance a lot (only works for Webpack 2.x).
In .ember-cli
, add these properties:
"liveReload": true,
"watcher": "polling"
or invoke the serve command using the polling watcher:
ember serve --watcher polling
Exactly what I was looking for thank you!