@@ -95,6 +95,7 @@ export default class ReactFlightWebpackPlugin {
95
95
}
96
96
97
97
apply ( compiler : any ) {
98
+ let resolvedClientReferences ;
98
99
const run = ( params , callback ) => {
99
100
// First we need to find all client files on the file system. We do this early so
100
101
// that we have them synchronously available later when we need them. This might
@@ -107,66 +108,63 @@ export default class ReactFlightWebpackPlugin {
107
108
contextResolver ,
108
109
compiler . inputFileSystem ,
109
110
compiler . createContextModuleFactory ( ) ,
110
- ( err , resolvedClientReferences ) => {
111
+ ( err , resolvedClientRefs ) => {
111
112
if ( err ) {
112
113
callback ( err ) ;
113
114
return ;
114
115
}
115
- compiler . hooks . compilation . tap (
116
- PLUGIN_NAME ,
117
- ( compilation , { normalModuleFactory} ) => {
118
- compilation . dependencyFactories . set (
119
- ClientReferenceDependency ,
120
- normalModuleFactory ,
121
- ) ;
122
- compilation . dependencyTemplates . set (
123
- ClientReferenceDependency ,
124
- new NullDependency . Template ( ) ,
125
- ) ;
126
-
127
- compilation . hooks . buildModule . tap ( PLUGIN_NAME , module => {
128
- // We need to add all client references as dependency of something in the graph so
129
- // Webpack knows which entries need to know about the relevant chunks and include the
130
- // map in their runtime. The things that actually resolves the dependency is the Flight
131
- // client runtime. So we add them as a dependency of the Flight client runtime.
132
- // Anything that imports the runtime will be made aware of these chunks.
133
- // TODO: Warn if we don't find this file anywhere in the compilation.
134
- if ( module . resource !== clientFileName ) {
135
- return ;
136
- }
137
- if ( resolvedClientReferences ) {
138
- for ( let i = 0 ; i < resolvedClientReferences . length ; i ++ ) {
139
- const dep = resolvedClientReferences [ i ] ;
140
- const chunkName = this . chunkName
141
- . replace ( / \[ i n d e x \] / g, '' + i )
142
- . replace (
143
- / \[ r e q u e s t \] / g,
144
- Template . toPath ( dep . userRequest ) ,
145
- ) ;
146
-
147
- const block = new AsyncDependenciesBlock (
148
- {
149
- name : chunkName ,
150
- } ,
151
- module ,
152
- null ,
153
- dep . require ,
154
- ) ;
155
- block . addDependency ( dep ) ;
156
- module . addBlock ( block ) ;
157
- }
158
- }
159
- } ) ;
160
- } ,
161
- ) ;
162
-
116
+ resolvedClientReferences = resolvedClientRefs ;
163
117
callback ( ) ;
164
118
} ,
165
119
) ;
166
120
} ;
167
121
168
122
compiler . hooks . run . tapAsync ( PLUGIN_NAME , run ) ;
169
123
compiler . hooks . watchRun . tapAsync ( PLUGIN_NAME , run ) ;
124
+ compiler . hooks . compilation . tap (
125
+ PLUGIN_NAME ,
126
+ ( compilation , { normalModuleFactory} ) => {
127
+ compilation . dependencyFactories . set (
128
+ ClientReferenceDependency ,
129
+ normalModuleFactory ,
130
+ ) ;
131
+ compilation . dependencyTemplates . set (
132
+ ClientReferenceDependency ,
133
+ new NullDependency . Template ( ) ,
134
+ ) ;
135
+
136
+ compilation . hooks . buildModule . tap ( PLUGIN_NAME , module => {
137
+ // We need to add all client references as dependency of something in the graph so
138
+ // Webpack knows which entries need to know about the relevant chunks and include the
139
+ // map in their runtime. The things that actually resolves the dependency is the Flight
140
+ // client runtime. So we add them as a dependency of the Flight client runtime.
141
+ // Anything that imports the runtime will be made aware of these chunks.
142
+ // TODO: Warn if we don't find this file anywhere in the compilation.
143
+ if ( module . resource !== clientFileName ) {
144
+ return ;
145
+ }
146
+ if ( resolvedClientReferences ) {
147
+ for ( let i = 0 ; i < resolvedClientReferences . length ; i ++ ) {
148
+ const dep = resolvedClientReferences [ i ] ;
149
+ const chunkName = this . chunkName
150
+ . replace ( / \[ i n d e x \] / g, '' + i )
151
+ . replace ( / \[ r e q u e s t \] / g, Template . toPath ( dep . userRequest ) ) ;
152
+
153
+ const block = new AsyncDependenciesBlock (
154
+ {
155
+ name : chunkName ,
156
+ } ,
157
+ module ,
158
+ null ,
159
+ dep . require ,
160
+ ) ;
161
+ block . addDependency ( dep ) ;
162
+ module . addBlock ( block ) ;
163
+ }
164
+ }
165
+ } ) ;
166
+ } ,
167
+ ) ;
170
168
171
169
compiler . hooks . emit . tap ( PLUGIN_NAME , compilation => {
172
170
const json = { } ;
0 commit comments