Is it possible to upload files directly to a gatsby site (specifically
the static folder) and trigger a rebuild?
Not by default. All the workarounds need to be attached to some watcher in the server since Gatsby doesn't provide this feature by default.
I think you can achieve what you are trying by using chokidar
(to watch folder changes) + chokidar-cli
(to run bash commands):
const chokidar = require('chokidar');
var watcher = chokidar.watch('your folder path', {ignored: /^\./, persistent: true});
watcher
.on('add', function(path) {console.log('File', path, 'has been added');})
.on('change', function(path) {console.log('File', path, 'has been changed');})
.on('unlink', function(path) {console.log('File', path, 'has been removed');})
.on('error', function(error) {console.error('Error happened', error);})
From Watch a folder for changes using node.js, and print file paths when they are changed
Regarding the chokidar-cli
, the -c
(or --command
) flag should do the trick:
Options: -c
, --command
Command to run after each change.
Needs to be surrounded with quotes when command contains spaces.
Instances of {path}
or {event}
within the command
will be replaced by the corresponding values from the
chokidar event.