
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
images-preload-plugins
Advanced tools
Images Preload Plugin 是一个用于在 Webpack 或者 Vite 构建过程中自动预加载或预获取图片资源的插件。通过配置不同的策略,可以在 HTML 文件中生成相应的 <link> 标签,以优化图片资源的加载性能。
使用 npm 安装插件:
npm install images-preload-plugins --save-dev
- strategy:预加载策略,可以是 'preload' 或 'prefetch'。
- assetDir:图片资源所在的目录路径。
// webpack.config.js
import WebpackPreloadImagesPlugin from 'images-preload-plugins/webpack';
// vite.config.js
import VitePreloadImagesPlugin from 'images-preload-plugins/vite';
// webpack.config.js
module.exports = {
// ...其他配置
plugins: [
new WebpackPreloadImagesPlugin([
{ strategy: 'preload', assetDir: 'src/assets/preload' },
{ strategy: 'prefetch', assetDir: 'src/assets/prefetch' },
]),
],
};
// vite.config.js
module.exports = defineConfig({
// ...其他配置
plugins: [
VitePreloadImagesPlugin([
{ strategy: 'preload', assetDir: 'src/assets/preload' },
{ strategy: 'prefetch', assetDir: 'src/assets/prefetch' },
]),
],
});
// options {}
// webpack.config.js
module.exports = {
//...其他配置
plugins: [
new WebpackPreloadImagesPlugin({
strategy: 'preload',
assetDir:'src/assets/preload'
}),
],
};
// vite.config.js
module.exports = defineConfig({
// ...其他配置
plugins: [
VitePreloadImagesPlugin({
strategy: 'preload',
assetDir:'src/assets/preload'
}),
],
});
- 对于 preload 策略
<link rel="preload" as="image" href="path/to/image.jpg">
- 对于 prefetch 策略
<link rel="prefetch" as="image" href="path/to/image.jpg">
- 确保 assetDir 路径正确,否则插件可能无法找到图片资源。
- 如果使用的是私有 npm 仓库,确保你有正确的访问权限。
欢迎贡献代码或提出问题!请在 GitHub 上提交 Pull Request 或 Issue。
FAQs
this is a plugins for webpack images preload or prefetch
The npm package images-preload-plugins receives a total of 11 weekly downloads. As such, images-preload-plugins popularity was classified as not popular.
We found that images-preload-plugins demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.