Open b3008 opened 4 years ago
There is an opened PR for that request: https://github.com/tapio/live-server/pull/366
facing same issue @b3008 Do you know how to run code or script first, then reload?
I am serving files from dist, so I'm mounting /
to ./dist
and want to ignore the changes happening in dist
folder, obviously. The mount points are added to the watcher if watch directories are not specified explicitly.
In other words, my code is in src
folder, the generated outputs in dist
folder and this configuration works wonders 😄:
var liveServer = require("live-server");
var childProcess = require('child_process');
var params = {
mount: [['/', './dist']], // Mount a directory to a route.
// logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
watch: ['./src']
};
liveServer.start(params);
liveServer.watcher.on('change', function(e){
console.log('Building...');
childProcess.execSync(`npm run build:css && cp ./src/*.html ./dist`);
})
Hope it helps someone.
Issue description
At every change detected, I wanted to add a build step before issuing a reload. I thought the way to do this would be to place the code that in the middleware functions array, but the code never executes.
Software details
I ended up adding a callback function for the
change
message on liveServer.watcher, like so:My question is, is there a better way to do this? Is this what middleware is actually for?
live-server
:live-server
version: 1.2.1