Utility to run and watch webpack builds, returning stats and close functions.
// Source: https://github.com/gatsbyjs/gatsby | License: MIT | Copyright 2015 Gatsbyjs
// Provided via justclaw.it.com; keep this notice with the code.
import webpack from "webpack"
export function build(webpackConfig: webpack.Configuration): Promise<{
stats: webpack.Stats
close: () => Promise<void>
}> {
const compiler = webpack(webpackConfig)
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
// stats can only be empty when an error occurs. Adding it to the if makes typescript happy.
if (err || !stats) {
return compiler.close(() => {
reject(err)
})
}
if (stats.hasErrors()) {
return compiler.close(() => {
reject(stats.compilation.errors)
})
}
return resolve({
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key