File tree Expand file tree Collapse file tree
add-lazy-runtime-module-error Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ module . exports = [ [ / r u n t i m e m o d u l e l o a d f a i l e d / ] ] ;
Original file line number Diff line number Diff line change 1+ it ( "should surface a failing runtime module load as a build error" , ( ) => {
2+ // the build error is asserted by errors.js
3+ } ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const PLUGIN_NAME = "AddLazyRuntimeModuleErrorTestPlugin" ;
4+
5+ /** @type {import("../../../../types").Configuration } */
6+ module . exports = {
7+ plugins : [
8+ {
9+ apply ( compiler ) {
10+ compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , ( compilation ) => {
11+ compilation . hooks . additionalTreeRuntimeRequirements . tap (
12+ PLUGIN_NAME ,
13+ ( chunk ) => {
14+ compilation . addLazyRuntimeModule (
15+ chunk ,
16+ ( ) => Promise . reject ( new Error ( "runtime module load failed" ) ) ,
17+ ( Ctor ) => new Ctor ( )
18+ ) ;
19+ }
20+ ) ;
21+ } ) ;
22+ }
23+ }
24+ ]
25+ } ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const RuntimeModule = require ( "../../../../lib/RuntimeModule" ) ;
4+
5+ // Loaded through `addLazyRuntimeModule`, so it must reach the chunk's runtime.
6+ class MarkerRuntimeModule extends RuntimeModule {
7+ constructor ( ) {
8+ super ( "lazy marker" ) ;
9+ }
10+
11+ /**
12+ * @returns {string } runtime code
13+ */
14+ generate ( ) {
15+ return 'globalThis.__lazyRuntimeMarker = "attached";' ;
16+ }
17+ }
18+
19+ module . exports = MarkerRuntimeModule ;
Original file line number Diff line number Diff line change 1+ it ( "should attach a runtime module queued through addLazyRuntimeModule" , ( ) => {
2+ expect ( globalThis . __lazyRuntimeMarker ) . toBe ( "attached" ) ;
3+ } ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const PLUGIN_NAME = "AddLazyRuntimeModuleTestPlugin" ;
4+
5+ /** @type {import("../../../../types").Configuration } */
6+ module . exports = {
7+ plugins : [
8+ {
9+ apply ( compiler ) {
10+ compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , ( compilation ) => {
11+ compilation . hooks . additionalTreeRuntimeRequirements . tap (
12+ PLUGIN_NAME ,
13+ ( chunk ) => {
14+ compilation . addLazyRuntimeModule (
15+ chunk ,
16+ ( ) => Promise . resolve ( require ( "./MarkerRuntimeModule" ) ) ,
17+ ( MarkerRuntimeModule ) => new MarkerRuntimeModule ( )
18+ ) ;
19+ }
20+ ) ;
21+ } ) ;
22+ }
23+ }
24+ ]
25+ } ;
You can’t perform that action at this time.
0 commit comments