Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle undefined configuration export #2930

Merged
merged 9 commits into from Sep 7, 2021
10 changes: 9 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -67,10 +67,18 @@ class WebpackCLI {
}

// For babel/typescript
if (result.default) {
if (result && result.default) {
result = result.default;
}

// Treat undefined configuration for zero-config
if (!result) {
this.logger.info(
"Configuration file provided didn't export any configuration, using defaults to build.",
);
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
result = {};
}

return result;
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
1 change: 1 addition & 0 deletions test/build/config/undefined/src/index.js
@@ -0,0 +1 @@
console.log("Percy Weasley")
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions test/build/config/undefined/undefined.test.js
@@ -0,0 +1,16 @@
"use strict";
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with undefined export config file", () => {
it("should throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
resolve(__dirname, "webpack.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config/undefined/webpack.config.js
@@ -0,0 +1 @@
module.exports = undefined;
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved