A vite plugin for prefetching resources
npm install vite-plugin-bundle-prefetchthere is no official rollup/vite plugin to work as the webpack prefetch plugin, we just have preload in vite, but we really need the prefetch for some Scenario.
some steps taken by vite-plugin-bundle-prefetch
- get all bundles which will include the assetsDir
- filter the target files (rm .map file or ignore the legacy build)
- get the final output html file content
- append the in head
- npm i vite-plugin-bundle-prefetch -D
- import in your vite.config.ts
``ts
// vite.config.js
import prefetchPlugin from 'vite-plugin-bundle-prefetch';
export default {
plugins: [prefetchPlugin()],
};
`
- Type:Function(assetName:string)=>booleanundefined
- Default:
- Desc: provide the customized method to exclude the files which will be added in index.html
`ts``
export default {
plugins: [
prefetchPlugin({
excludeFn: (assetName) => {
return assetName.includes('ApproveRecords');
},
}),
],
};