File tree Expand file tree Collapse file tree
aggressive-splitting-on-demand Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,13 +16,15 @@ var REPLACEMENTS = {
1616 __webpack_modules__ : "__webpack_require__.m" , // eslint-disable-line camelcase
1717 __webpack_chunk_load__ : "__webpack_require__.e" , // eslint-disable-line camelcase
1818 __non_webpack_require__ : "require" , // eslint-disable-line camelcase
19+ __webpack_nonce__ : "__webpack_require__.nc" , // eslint-disable-line camelcase
1920 "require.onError" : "__webpack_require__.oe" // eslint-disable-line camelcase
2021} ;
2122var REPLACEMENT_TYPES = {
2223 __webpack_public_path__ : "string" , // eslint-disable-line camelcase
2324 __webpack_require__ : "function" , // eslint-disable-line camelcase
2425 __webpack_modules__ : "object" , // eslint-disable-line camelcase
25- __webpack_chunk_load__ : "function" // eslint-disable-line camelcase
26+ __webpack_chunk_load__ : "function" , // eslint-disable-line camelcase
27+ __webpack_nonce__ : "string" // eslint-disable-line camelcase
2628} ;
2729var IGNORES = [ ] ;
2830APIPlugin . prototype . apply = function ( compiler ) {
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
3939 "script.async = true;" ,
4040 "script.timeout = " + chunkLoadTimeout + ";" ,
4141 crossOriginLoading ? "script.crossOrigin = '" + crossOriginLoading + "';" : "" ,
42+ "if (" + this . requireFn + ".nc) {" ,
43+ this . indent ( "script.setAttribute(\"nonce\", " + this . requireFn + ".nc);" ) ,
44+ "}" ,
4245 "script.src = " + this . requireFn + ".p + " +
4346 this . applyPluginsWaterfall ( "asset-path" , JSON . stringify ( chunkFilename ) , {
4447 hash : "\" + " + this . renderCurrentHashCode ( hash ) + " + \"" ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ var Template = require("./Template");
1919// __webpack_require__.n = compatibility get default export
2020// __webpack_require__.h = the webpack hash
2121// __webpack_require__.oe = the uncatched error handler for the webpack runtime
22+ // __webpack_require__.nc = the script nonce
2223
2324function MainTemplate ( outputOptions ) {
2425 Template . call ( this , outputOptions ) ;
Original file line number Diff line number Diff line change 1+ it ( "should load script with nonce 'nonce1234'" , function ( done ) {
2+ __webpack_nonce__ = 'nonce1234' ;
3+ require . ensure ( [ ] , function ( require ) {
4+ require ( "./empty?a" ) ;
5+ } , "chunk-with-nonce" ) ;
6+ __webpack_nonce__ = undefined ;
7+ // if in browser context, test that nonce was added.
8+ if ( typeof document !== 'undefined' ) {
9+ var script = document . querySelector ( 'script[src="js/chunk-with-nonce.web.js"]' ) ;
10+ script . getAttribute ( 'nonce' ) . should . be . eql ( 'nonce1234' ) ;
11+ }
12+ __webpack_nonce__ = undefined ;
13+ done ( ) ;
14+ } ) ;
15+
16+ it ( "should load script without nonce" , function ( done ) {
17+ require . ensure ( [ ] , function ( require ) {
18+ require ( "./empty?b" ) ;
19+ } , "chunk-without-nonce" ) ;
20+
21+ // if in browser context, test that nonce was added.
22+ if ( typeof document !== 'undefined' ) {
23+ var script = document . querySelector ( 'script[src="js/chunk-without-nonce.web.js"]' ) ;
24+ script . hasAttribute ( 'nonce' ) . should . be . eql ( false ) ;
25+ }
26+ __webpack_nonce__ = undefined ;
27+ done ( ) ;
28+ } ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Time: Xms
665ae9e18455b866684bd0.js 1.94 kB 2 [emitted]
77e91ec4902ca3057b42bb.js 1.93 kB 3 [emitted]
880947f0875d56ab0bfe02.js 977 bytes 4 [emitted]
9- 6335d9dcc7fa048743b7.js 7.01 kB 6 [emitted] main
9+ 6335d9dcc7fa048743b7.js 7.13 kB 6 [emitted] main
1010cf500be0e585f01d2ccb.js 983 bytes 9 [emitted]
1111a7bfb642a544b4302cc4.js 975 bytes 11 [emitted]
1212Entrypoint main = 6335d9dcc7fa048743b7.js
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Time: Xms
440.bundle.js 227 bytes 0 [emitted]
551.bundle.js 106 bytes 1 [emitted]
662.bundle.js 200 bytes 2 [emitted]
7- bundle.js 5.65 kB 3 [emitted] main
7+ bundle.js 5.77 kB 3 [emitted] main
88chunk {0} 0.bundle.js 54 bytes {3} [rendered]
99 > [5] (webpack)/test/statsCases/chunks/index.js 3:0-16
1010 [2] (webpack)/test/statsCases/chunks/c.js 54 bytes {0} [built]
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Time: Xms
88 4.js 136 bytes 4, 6 [emitted] chunk
99 5.js 293 bytes 5, 3 [emitted] cir2 from cir1
1010 6.js 78 bytes 6 [emitted] ac in ab
11- main.js 6.25 kB 7 [emitted] main
11+ main.js 6.37 kB 7 [emitted] main
1212chunk {0} 0.js (cir1) 81 bytes {7} {5} {3} [rendered]
1313 > duplicate cir1 from cir2 [3] (webpack)/test/statsCases/optimize-chunks/circular2.js 1:0-79
1414 > duplicate cir1 [8] (webpack)/test/statsCases/optimize-chunks/index.js 13:0-54
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Time: Xms
44 0.js 227 bytes 0 [emitted]
55 1.js 106 bytes 1 [emitted]
66 2.js 200 bytes 2 [emitted]
7- main.js 5.64 kB 3 [emitted] main
7+ main.js 5.76 kB 3 [emitted] main
88Entrypoint main = main.js
99chunk {0} 0.js 54 bytes {3} [rendered]
1010 [2] (webpack)/test/statsCases/preset-verbose/c.js 54 bytes {0} [built]
You can’t perform that action at this time.
0 commit comments