File tree Expand file tree Collapse file tree
test/configCases/side-effects/pure-deferred-import Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2866,10 +2866,7 @@ ${defineGetters}`
28662866 result . add (
28672867 `\n;// ${ info . module . readableIdentifier (
28682868 requestShortener
2869- ) } \n${ runtimeTemplate . moduleSideEffectsAnnotation (
2870- info . module ,
2871- moduleGraph
2872- ) } ${ info . namespaceFnName } ();\n`
2869+ ) } \n${ info . namespaceFnName } ();\n`
28732870 ) ;
28742871 } else if ( ! info . wrapped ) {
28752872 result . add (
@@ -2948,10 +2945,7 @@ ${defineGetters}`
29482945 result . add (
29492946 `\n;// EXTERNAL MODULE: ${ info . module . readableIdentifier (
29502947 requestShortener
2951- ) } \n${ runtimeTemplate . moduleSideEffectsAnnotation (
2952- info . module ,
2953- moduleGraph
2954- ) } ${ info . namespaceFnName } ();\n`
2948+ ) } \n${ info . namespaceFnName } ();\n`
29552949 ) ;
29562950 }
29572951 // If a module is deferred in other places, but used as non-deferred here,
Original file line number Diff line number Diff line change 1+ import { readLazy } from "./lib.js" ;
2+
3+ const fs = require ( "fs" ) ;
4+ const path = require ( "path" ) ;
5+
6+ const read = ( name ) =>
7+ fs . readFileSync ( path . join ( path . dirname ( __filename ) , name ) , "utf-8" ) ;
8+
9+ it ( "should evaluate the deferred module on access" , ( ) => {
10+ expect ( readLazy ( 6 , 7 ) ) . toBe ( 43 ) ;
11+ } ) ;
12+
13+ it ( "should annotate a deferred import" , ( ) => {
14+ expect ( read ( "bundle0.js" ) ) . toMatch (
15+ / d e f e r r e d h a r m o n y i m p o r t \* \/ v a r \w + = \/ \* # _ _ P U R E _ _ \* \/ _ _ w e b p a c k _ r e q u i r e _ _ \. z O \( /
16+ ) ;
17+ } ) ;
18+
19+ it ( "should annotate a deferred module a concatenation reaches" , ( ) => {
20+ expect ( read ( "bundle1.js" ) ) . toMatch (
21+ / D E F E R R E D E X T E R N A L M O D U L E : \. \/ p u r e - c j s \. j s \n v a r \w + = \/ \* # _ _ P U R E _ _ \* \/ _ _ w e b p a c k _ r e q u i r e _ _ \. z O \( /
22+ ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as lazy from /* webpackDefer: true */ "./pure-cjs" ;
2+ import { extra } from "./side.js" ;
3+
4+ export function readLazy ( a , b ) {
5+ return lazy . mul ( a , b ) + extra ( 0 ) ;
6+ }
Original file line number Diff line number Diff line change 1+ exports . mul = function ( a , b ) {
2+ return a * b ;
3+ } ;
Original file line number Diff line number Diff line change 1+ export function extra ( a ) {
2+ return a + 1 ;
3+ }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const target = `async-node${ process . versions . node . split ( "." ) . map ( Number ) [ 0 ] } ` ;
4+
5+ /** @type {import("../../../../types").Configuration[] } */
6+ module . exports = [
7+ {
8+ name : "plain" ,
9+ target,
10+ mode : "production" ,
11+ experiments : { deferImport : true } ,
12+ optimization : {
13+ // Renders the deferred import through `importStatement`.
14+ concatenateModules : false
15+ }
16+ } ,
17+ {
18+ name : "concatenated" ,
19+ target,
20+ mode : "production" ,
21+ experiments : { deferImport : true } ,
22+ // A CommonJS module cannot join the concatenation, so it stays an external
23+ // member of it and `ConcatenatedModule` renders the deferred loader itself.
24+ optimization : { concatenateModules : true }
25+ }
26+ ] ;
You can’t perform that action at this time.
0 commit comments