Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5196 from AndersDJohnson/multi-compiler-functions
feat: support config functions with multi-compiler
- Loading branch information
Showing
7 changed files
with
49 additions
and
8 deletions.
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,29 @@ | ||
"use strict"; | ||
|
||
module.exports = function prepareOptions(options, argv) { | ||
argv = argv || {}; | ||
|
||
options = handleExport(options); | ||
|
||
if(Array.isArray(options)) { | ||
options = options.map(_options => handleFunction(_options, argv)); | ||
} else { | ||
options = handleFunction(options, argv); | ||
} | ||
return options; | ||
}; | ||
|
||
function handleExport(options) { | ||
const isES6DefaultExported = ( | ||
typeof options === "object" && options !== null && typeof options.default !== "undefined" | ||
); | ||
options = isES6DefaultExported ? options.default : options; | ||
return options; | ||
} | ||
|
||
function handleFunction(options, argv) { | ||
if(typeof options === "function") { | ||
options = options(argv.env, argv); | ||
} | ||
return options; | ||
} |
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
3 changes: 3 additions & 0 deletions
3
test/configCases/simple/multi-compiler-functions-export/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,3 @@ | ||
it("should run a multi compiler with functions with export default", function() { | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/configCases/simple/multi-compiler-functions-export/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,5 @@ | ||
exports.default = [ | ||
function() { | ||
return {}; | ||
} | ||
]; |
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 @@ | ||
it("should run a multi compiler with functions", function() { | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/configCases/simple/multi-compiler-functions/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,5 @@ | ||
module.exports = [ | ||
function() { | ||
return {}; | ||
} | ||
]; |