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 #6793 from ronkorving/define-functions
DefinePlugin: add ability to use function return values
- Loading branch information
Showing
11 changed files
with
147 additions
and
42 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
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 @@ | ||
123 |
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 @@ | ||
321 |
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,15 @@ | ||
it("should be able to use dynamic defines in watch mode", function() { | ||
const module = require("./module"); | ||
module.should.be.eql({ | ||
default: WATCH_STEP, | ||
type: "string" | ||
}); | ||
}); | ||
|
||
it("should not update a define when dependencies list is missing", function() { | ||
const module2 = require("./module2"); | ||
module2.should.be.eql({ | ||
default: "0", | ||
type: "string" | ||
}); | ||
}); |
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,2 @@ | ||
export default TEST_VALUE; | ||
export const type = typeof TEST_VALUE; |
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,2 @@ | ||
export default TEST_VALUE2; | ||
export const type = typeof TEST_VALUE2; |
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 @@ | ||
0 |
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 @@ | ||
1 |
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,22 @@ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const webpack = require("../../../../"); | ||
const valueFile = path.resolve( | ||
__dirname, | ||
"../../../js/watch-src/plugins/define-plugin/value.txt" | ||
); | ||
module.exports = { | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
TEST_VALUE: webpack.DefinePlugin.runtimeValue( | ||
() => { | ||
return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim()); | ||
}, | ||
[valueFile] | ||
), | ||
TEST_VALUE2: webpack.DefinePlugin.runtimeValue(() => { | ||
return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim()); | ||
}, []) | ||
}) | ||
] | ||
}; |