-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ca2e0f
commit 711661c
Showing
12 changed files
with
99 additions
and
4 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
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,31 @@ | ||
use rspack_core::{ | ||
impl_runtime_module, | ||
rspack_sources::{BoxSource, RawSource, SourceExt}, | ||
Compilation, RuntimeGlobals, RuntimeModule, | ||
}; | ||
use rspack_identifier::Identifier; | ||
|
||
#[derive(Debug, Eq)] | ||
pub struct NonceRuntimeModule { | ||
id: Identifier, | ||
} | ||
|
||
impl Default for NonceRuntimeModule { | ||
fn default() -> Self { | ||
Self { | ||
id: Identifier::from("webpack/runtime/nonce"), | ||
} | ||
} | ||
} | ||
|
||
impl RuntimeModule for NonceRuntimeModule { | ||
fn name(&self) -> Identifier { | ||
self.id | ||
} | ||
|
||
fn generate(&self, _: &Compilation) -> BoxSource { | ||
RawSource::from(format!("{} = undefined;", RuntimeGlobals::SCRIPT_NONCE)).boxed() | ||
} | ||
} | ||
|
||
impl_runtime_module!(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
Empty file.
12 changes: 12 additions & 0 deletions
12
packages/rspack/tests/configCases/nonce/not-set-nonce/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,12 @@ | ||
it("should load script without nonce", function () { | ||
__webpack_nonce__ = undefined; | ||
const promise = import( | ||
"./empty?a" /* webpackChunkName: "chunk-without-nonce" */ | ||
); | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./chunk-without-nonce.web.js"); | ||
expect(script.getAttribute("nonce")).toBeUndefined(); | ||
|
||
return promise; | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/rspack/tests/configCases/nonce/not-set-nonce/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,11 @@ | ||
module.exports = { | ||
target: "web", | ||
output: { | ||
chunkFilename: "chunk-without-nonce.web.js", | ||
crossOriginLoading: "anonymous", | ||
trustedTypes: true | ||
}, | ||
optimization: { | ||
minimize: false | ||
} | ||
}; |
Empty file.
12 changes: 12 additions & 0 deletions
12
packages/rspack/tests/configCases/nonce/set-nonce/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,12 @@ | ||
it("should load script with nonce 'nonce1234'", function () { | ||
__webpack_nonce__ = "nonce1234"; | ||
const promise = import( | ||
"./empty?a" /* webpackChunkName: "chunk-with-nonce" */ | ||
); | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./chunk-with-nonce.web.js"); | ||
expect(script.getAttribute("nonce")).toBe("nonce1234"); | ||
|
||
return promise; | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/rspack/tests/configCases/nonce/set-nonce/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,11 @@ | ||
module.exports = { | ||
target: "web", | ||
output: { | ||
chunkFilename: "chunk-with-nonce.web.js", | ||
crossOriginLoading: "anonymous", | ||
trustedTypes: true | ||
}, | ||
optimization: { | ||
minimize: false | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.