@@ -25,29 +25,33 @@ const refreshUtilsPath = path.join(__dirname, '../runtime/RefreshUtils');
25
25
function injectRefreshLoader ( moduleData , injectOptions ) {
26
26
const { match, options } = injectOptions ;
27
27
28
+ // Include and exclude user-specified files
29
+ if ( ! match ( moduleData . matchResource || moduleData . resource ) ) return moduleData ;
30
+ // Include and exclude dynamically generated modules from other loaders
31
+ if ( moduleData . matchResource && ! match ( moduleData . request ) ) return moduleData ;
32
+ // Exclude files referenced as assets
33
+ if ( moduleData . type . includes ( 'asset' ) ) return moduleData ;
34
+ // Check to prevent double injection
35
+ if ( moduleData . loaders . find ( ( { loader } ) => loader === resolvedLoader ) ) return moduleData ;
36
+ // Skip react-refresh and the plugin's runtime utils to prevent self-referencing -
37
+ // this is useful when using the plugin as a direct dependency,
38
+ // or when node_modules are specified to be processed.
28
39
if (
29
- // Include and exclude user-specified files
30
- match ( moduleData . matchResource || moduleData . resource ) &&
31
- // Exclude files referenced as assets
32
- ! moduleData . type . includes ( 'asset' ) &&
33
- // Skip react-refresh and the plugin's runtime utils to prevent self-referencing -
34
- // this is useful when using the plugin as a direct dependency,
35
- // or when node_modules are specified to be processed.
36
- ! moduleData . resource . includes ( reactRefreshPath ) &&
37
- ! moduleData . resource . includes ( refreshUtilsPath ) &&
38
- // Check to prevent double injection
39
- ! moduleData . loaders . find ( ( { loader } ) => loader === resolvedLoader )
40
+ moduleData . resource . includes ( reactRefreshPath ) ||
41
+ moduleData . resource . includes ( refreshUtilsPath )
40
42
) {
41
- // As we inject runtime code for each module,
42
- // it is important to run the injected loader after everything.
43
- // This way we can ensure that all code-processing have been done,
44
- // and we won't risk breaking tools like Flow or ESLint.
45
- moduleData . loaders . unshift ( {
46
- loader : resolvedLoader ,
47
- options,
48
- } ) ;
43
+ return moduleData ;
49
44
}
50
45
46
+ // As we inject runtime code for each module,
47
+ // it is important to run the injected loader after everything.
48
+ // This way we can ensure that all code-processing have been done,
49
+ // and we won't risk breaking tools like Flow or ESLint.
50
+ moduleData . loaders . unshift ( {
51
+ loader : resolvedLoader ,
52
+ options,
53
+ } ) ;
54
+
51
55
return moduleData ;
52
56
}
53
57
0 commit comments