Skip to content

Instantly share code, notes, and snippets.

@moos
Created January 14, 2021 20:46
Show Gist options
  • Save moos/8f63c9dcd090a152fe585844cd602cae to your computer and use it in GitHub Desktop.
Save moos/8f63c9dcd090a152fe585844cd602cae to your computer and use it in GitHub Desktop.
Hot reload and do full builds with `esbuild` for WSL
const { build } = require('esbuild');
const liveServer = require('live-server');
var watch = require('node-watch');
async function fullBuild() {
const builder = await build({
color: true,
entryPoints: ['./src/index.js'],
outfile: './build/app.js',
minify: false,
bundle: true,
sourcemap: false,
// logLevel: 'error',
// incremental: true
});
}
fullBuild();
watch('src', {
recursive: true,
filter: /\.(js|html|css)$/
}, function(evt, name) {
console.log('%s changed.', name);
fullBuild();
});
liveServer.start({
root: '.',
file: 'src/index.html',
wait: 1000,
logLevel: 2,
open: false,
});
@moos
Copy link
Author

moos commented Jan 14, 2021

Inspired by unki2aut/serve.js.

@moos
Copy link
Author

moos commented Jan 15, 2021

OK - this does work, except for the hot-reload part. chokidar chokes on mounted drives (/mnt/c/dev/foo) and so live-server (which uses chokidar internally) is unable to get file changes.

If you're using mounted drives, suggest using @unki2aut's script with the { usePolling: true} chokidar option, and up-voting this list-server issue or patching it yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment