-
-
Notifications
You must be signed in to change notification settings - Fork 621
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
feat: sharabale configs #2868
Closed
Closed
feat: sharabale configs #2868
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
"use strict"; | ||
|
||
const { run } = require("../../utils/test-utils"); | ||
|
||
describe("extends", () => { | ||
it("should use webpack.config.js and use all extended configs", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, []); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use multi-extended.config.js and use all extended configs", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./multi-extended.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("multi-extended.config.js"); | ||
expect(stdout).toContain("one.webpack.config.js"); | ||
expect(stdout).toContain("two.webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use extend configuration with --extends flag", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--extends", | ||
"./first-webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use extend multiple configurations with --extends flag", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--extends", | ||
"./one.webpack.config.js", | ||
"--extends", | ||
"./two.webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("one.webpack.config.js"); | ||
expect(stdout).toContain("two.webpack.config.js"); | ||
}); | ||
|
||
it("should work in multi compiler mode", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./multi-compiler.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
// config names | ||
expect(stdout).toContain("multi-compiler.config.js"); | ||
expect(stdout).toContain("webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
// compiler names | ||
expect(stdout).toContain("first-compiler"); | ||
expect(stdout).toContain("second-compiler"); | ||
}); | ||
|
||
it("should work in multi compiler mode with --config-name", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./multi-compiler.config.js", | ||
"--config-name", | ||
"second-compiler", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
// config names | ||
expect(stdout).toContain("multi-compiler.config.js"); | ||
expect(stdout).toContain("webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
// compiler names | ||
expect(stdout).not.toContain("first-compiler"); | ||
expect(stdout).toContain("second-compiler"); | ||
}); | ||
|
||
it("should work with multiple --config flags", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--config", | ||
"./webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should work with multiple --merge flag", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--config", | ||
"./second-webpack.config.js", | ||
"--merge", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use extend multiple configurations with --extends flag #2", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--extends", | ||
"./one.webpack.config.js", | ||
"--extends", | ||
"./two.webpack.config.js", | ||
"--extends", | ||
"./second-webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("one.webpack.config.js"); | ||
expect(stdout).toContain("two.webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use extend configuration with -e alias", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"-e", | ||
"./first-webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("first-webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should use extend multiple configurations with -e alias", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"-e", | ||
"./one.webpack.config.js", | ||
"-e", | ||
"./two.webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("one.webpack.config.js"); | ||
expect(stdout).toContain("two.webpack.config.js"); | ||
}); | ||
|
||
it("should use extend multiple configurations with -e alias #2", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./simple-webpack.config.js", | ||
"--extends", | ||
"./one.webpack.config.js", | ||
"--extends", | ||
"./two.webpack.config.js", | ||
"--extends", | ||
"./second-webpack.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain("simple-webpack.config.js"); | ||
expect(stdout).toContain("one.webpack.config.js"); | ||
expect(stdout).toContain("two.webpack.config.js"); | ||
expect(stdout).toContain("second-webpack.config.js"); | ||
expect(stdout).toContain("third-webpack.config.js"); | ||
}); | ||
|
||
it("should throw an error for invalid-extend.config.js", async () => { | ||
const { exitCode, stderr, stdout } = await run(__dirname, [ | ||
"--config", | ||
"./invalid-extend.config.js", | ||
]); | ||
|
||
expect(exitCode).toBe(2); | ||
expect(stderr).toContain(`Error: Cannot find module`); | ||
expect(stdout).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require("path"); | ||
|
||
module.exports = () => { | ||
console.log("first-webpack.config.js"); | ||
|
||
return { | ||
mode: "development", | ||
entry: "./src/first.js", | ||
extends: [path.resolve(__dirname, "./second-webpack.config.js")], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ["./invalid-config.js"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = () => { | ||
console.log("multi-compiler.config.js"); | ||
|
||
return [ | ||
{ | ||
mode: "development", | ||
entry: "./src/first.js", | ||
name: "first-compiler", | ||
}, | ||
{ | ||
mode: "development", | ||
entry: "./src/second.js", | ||
name: "second-compiler", | ||
extends: ["./webpack.config.js"], | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = () => { | ||
console.log("multi-extended.config.js"); | ||
|
||
return { | ||
extends: [ | ||
"./one.webpack.config.js", | ||
"./two.webpack.config.js", | ||
"./second-webpack.config.js", | ||
], | ||
target: "node", | ||
entry: "./src/multi.js", | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = () => { | ||
console.log("one.webpack.config.js"); | ||
|
||
return { | ||
mode: "development", | ||
entry: "./src/first.js", | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require("path"); | ||
|
||
module.exports = () => { | ||
console.log("second-webpack.config.js"); | ||
|
||
return { | ||
mode: "development", | ||
entry: "./src/second.js", | ||
extends: [path.resolve(__dirname, "./third-webpack.config.js")], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = () => { | ||
console.log("simple-webpack.config.js"); | ||
|
||
return { | ||
mode: "development", | ||
entry: "./src/index.js", | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("first.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("index"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("multi"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("second"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("third"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = () => { | ||
console.log("third-webpack.config.js"); | ||
|
||
return { | ||
stats: "detalied", | ||
entry: "./src/third.js", | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = () => { | ||
console.log("two.webpack.config.js"); | ||
|
||
return { | ||
mode: "development", | ||
entry: "./src/second.js", | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not use
webpack-merge
logic here? it is working goodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need to load the extended configurations, here we have only
paths
for extended configurations and not theiroptions
.Or am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally
--extends
means--config=webpack.config.js --config=webpack.other.config.js --merge
, so I think we already have logic for this, for the next major release we will change logic for multiple--config
https://github.com/webpack/webpack-cli/blob/master/packages/webpack-cli/lib/webpack-cli.js#L1619, I think we will throw an error on two and more config options without--merge
, but we can reuse this logic for--extends
,--extends
like syntax sugar, also do not forget--extends
in CLI should overrideextends
onwebpack.config.js
(I think eslint works the same, but need check)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will refactor 👍🏻 .