-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: skip prenonnect when HTML is disabled (#2011)
- Loading branch information
1 parent
974863d
commit db67c92
Showing
1 changed file
with
23 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
import { isHtmlDisabled } from '@rsbuild/shared'; | ||
import type { RsbuildPlugin } from '../types'; | ||
|
||
export const pluginNetworkPerformance = (): RsbuildPlugin => ({ | ||
name: 'rsbuild:network-performance', | ||
|
||
setup(api) { | ||
api.modifyBundlerChain( | ||
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker }) => { | ||
const config = api.getNormalizedConfig(); | ||
const { | ||
performance: { dnsPrefetch, preconnect }, | ||
} = config; | ||
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => { | ||
const config = api.getNormalizedConfig(); | ||
const { | ||
performance: { dnsPrefetch, preconnect }, | ||
} = config; | ||
|
||
if (isServer || isWebWorker || isServiceWorker) { | ||
return; | ||
} | ||
if (isHtmlDisabled(config, target)) { | ||
return; | ||
} | ||
|
||
const { HtmlNetworkPerformancePlugin } = await import( | ||
'../rspack/HtmlNetworkPerformancePlugin' | ||
); | ||
const { HtmlNetworkPerformancePlugin } = await import( | ||
'../rspack/HtmlNetworkPerformancePlugin' | ||
); | ||
|
||
if (dnsPrefetch) { | ||
chain | ||
.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH) | ||
.use(HtmlNetworkPerformancePlugin, [dnsPrefetch, 'dnsPrefetch']); | ||
} | ||
if (dnsPrefetch) { | ||
chain | ||
.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH) | ||
.use(HtmlNetworkPerformancePlugin, [dnsPrefetch, 'dnsPrefetch']); | ||
} | ||
|
||
if (preconnect) { | ||
chain | ||
.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT) | ||
.use(HtmlNetworkPerformancePlugin, [preconnect, 'preconnect']); | ||
} | ||
}, | ||
); | ||
if (preconnect) { | ||
chain | ||
.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT) | ||
.use(HtmlNetworkPerformancePlugin, [preconnect, 'preconnect']); | ||
} | ||
}); | ||
}, | ||
}); |