Skip to content

Commit

Permalink
fix: rewrited callback func in promise from callback func
Browse files Browse the repository at this point in the history
fixed to wait until webpack compilation or serving process is complete.
  • Loading branch information
kotarella1110 committed Sep 19, 2019
1 parent 502be4f commit fd493bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
24 changes: 13 additions & 11 deletions src/webpackCompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ module.exports = async (ctx: any) => {
argv.webpackConfig || argv.w,
);
const compiler = webpack(customWebpackConfig);

compiler.run((err, stats) => {
if (err) {
throw err;
}
console.log(
stats.toString({
chunks: false,
colors: true,
}),
);
await new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
reject(err);
}
console.log(
stats.toString({
chunks: false,
colors: true,
}),
);
resolve();
});
});
};
13 changes: 8 additions & 5 deletions src/webpackServe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ module.exports = async (ctx: any) => {

const compiler = webpack(webpackConfig);
const server = new WebpackDevServer(compiler, devServerConfig);
server.listen(port, host, err => {
if (err) {
throw err;
}
console.log('Starting the development server...\n');
await new Promise((resolve, reject) => {
server.listen(port, host, err => {
if (err) {
reject(err);
}
console.log('Starting the development server...\n');
resolve();
});
});
};

0 comments on commit fd493bf

Please sign in to comment.