Created
January 14, 2021 20:46
-
-
Save moos/8f63c9dcd090a152fe585844cd602cae to your computer and use it in GitHub Desktop.
Hot reload and do full builds with `esbuild` for WSL
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
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, | |
}); |
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
Inspired by unki2aut/serve.js.