Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Options:
--progress [value] Print compilation progress during build.
--prefetch <value> Prefetch this request.
-j, --json [value] Prints result as JSON or store it in a file.
--no-fail-on-warnings Negative 'fail-on-warnings' option.
--no-amd Negative 'amd' option.
--bail Report the first error as a hard error instead of tolerating it.
--no-bail Negative 'bail' option.
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ interface WebpackRunOptions extends WebpackOptionsNormalized {
json?: boolean;
argv?: Argv;
env: Env;
failOnWarnings?: boolean;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,17 @@ class WebpackCLI implements IWebpackCLI {
description: "Stop watching when stdin stream has ended.",
negatedDescription: "Do not stop watching when stdin stream has ended.",
},
{
name: "fail-on-warnings",
configs: [
{
type: "enum",
values: [false],
},
],
negative: true,
description: "Stop webpack-cli process with non-zero exit code on warnings from webpack",
},
];

// Extract all the flags being exported from core.
Expand Down Expand Up @@ -2478,6 +2489,10 @@ class WebpackCLI implements IWebpackCLI {
this.logger.raw(printedStats);
}
}

if (options.failOnWarnings && (stats.hasErrors() || stats.hasWarnings())) {
process.exit(1);
}
};

const env =
Expand Down
9 changes: 9 additions & 0 deletions test/build/build-warnings/warnings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ describe("warnings", () => {
expect(stdout).toMatch(/Error: Can't resolve/);
});

it("should exit with non-zero code on --fail-on-warnings flag", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--fail-on-warnings"]);

expect(exitCode).toBe(1);
expect(stderr).toBeFalsy();
expect(stdout).toMatch(/WARNING/);
expect(stdout).toMatch(/Error: Can't resolve/);
});

it('should output JSON with the "json" flag', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--json"]);

Expand Down