Skip to content

Commit

Permalink
Merge pull request #15483 from storybookjs/fix/15227-storybook-hangs-…
Browse files Browse the repository at this point in the history
…on-angular

Webpack5: Quit process after finishing a static build
  • Loading branch information
shilman committed Jul 7, 2021
1 parent b62b718 commit 63ad9f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/angular/src/server/build.ts
@@ -1,4 +1,13 @@
import { buildStatic } from '@storybook/core/server';
import { logger } from '@storybook/node-logger';
import options from './options';

buildStatic(options);
async function build() {
try {
await buildStatic(options);
} catch (error) {
logger.error(error);
}
}

build();
23 changes: 19 additions & 4 deletions lib/builder-webpack5/src/index.ts
Expand Up @@ -121,14 +121,19 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
const config = await getConfig(options);

return new Promise((succeed, fail) => {
webpackInstance(config).run((error, stats) => {
const compiler = webpackInstance(config);

compiler.run((error, stats) => {
if (error || !stats || stats.hasErrors()) {
logger.error('=> Failed to build the preview');
process.exitCode = 1;

if (error) {
logger.error(error.message);
return fail(error);

compiler.close(() => fail(error));

return;
}

if (stats && (stats.hasErrors() || stats.hasWarnings())) {
Expand All @@ -137,7 +142,9 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
errors.forEach((e) => logger.error(e.message));
warnings.forEach((e) => logger.error(e.message));

return fail(stats);
compiler.close(() => fail(stats));

return;
}
}

Expand All @@ -146,7 +153,15 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
stats.toJson({ warnings: true }).warnings.forEach((e) => logger.warn(e.message));
}

return succeed(stats);
// https://webpack.js.org/api/node/#run
// #15227
compiler.close((closeErr) => {
if (closeErr) {
return fail(closeErr);
}

return succeed(stats);
});
});
});
};
Expand Down

0 comments on commit 63ad9f3

Please sign in to comment.