Created
January 22, 2023 21:54
-
-
Save kevinfiol/e692502aec6e0c2402607bcc68f8babe to your computer and use it in GitHub Desktop.
esbuild w context
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
/** @type {esbuild.BuildOptions} **/ | |
const config = { | |
format: 'iife', | |
entryPoints: [ENTRY], | |
outfile: OUTFILE, | |
bundle: false, | |
plugins: [{ | |
name: 'on-end', | |
setup(build) { | |
build.onEnd(({ errors }) => { | |
if (errors[0]) logError(errors[0]); | |
else logSuccess(); | |
}) | |
} | |
}] | |
}; | |
const ctx = await esbuild.context(config); | |
if (DEV) { | |
// enable watch mode | |
// await ctx.watch(); | |
// enable server | |
await ctx.serve({ | |
port: SERVE_PORT, | |
servedir: SERVE_DIR | |
}).then(() => { | |
console.log(`Serving [${SERVE_DIR}] at http://localhost:${SERVE_PORT}`) | |
}); | |
// free up resources on close | |
process.on('exit', ctx.dispose); | |
} else { | |
// run build once && dispose context | |
await ctx.rebuild().finally(ctx.dispose); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment