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 #15802 from webpack/fix-nonce
add NonceRuntimeModule
- Loading branch information
Showing
5 changed files
with
44 additions
and
0 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,24 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Ivan Kopeykin @vankop | ||
*/ | ||
|
||
"use strict"; | ||
|
||
const RuntimeGlobals = require("../RuntimeGlobals"); | ||
const RuntimeModule = require("../RuntimeModule"); | ||
|
||
class NonceRuntimeModule extends RuntimeModule { | ||
constructor() { | ||
super("nonce", RuntimeModule.STAGE_ATTACH); | ||
} | ||
|
||
/** | ||
* @returns {string} runtime code | ||
*/ | ||
generate() { | ||
return `${RuntimeGlobals.scriptNonce} = undefined;`; | ||
} | ||
} | ||
|
||
module.exports = NonceRuntimeModule; |
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 @@ | ||
import "./nonce"; | ||
|
||
it("should set nonce", () => { | ||
expect(__webpack_nonce__).toBe("nonce"); | ||
}); |
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 @@ | ||
__webpack_nonce__ = "nonce"; |
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,7 @@ | ||
const webpack = require("../../../../"); | ||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = { | ||
target: "web", | ||
// plugin that intercepts __webpack_require__ | ||
plugins: [new webpack.HotModuleReplacementPlugin()] | ||
}; |