UNPKG

vite-css-preload-plugin

Version:

a vite plugin for css preload

29 lines (16 loc) 1.4 kB
1、这是一个给 vite 用的 css 预加载插件。 2、它的原理是在你打包完之后,去读取你产物的 html 文件里的 css link,然后生成对应的 preload link 来实现进准预加载。 3、由于 vite 会自己在 html 里注入一些 css link。所以在实现 css 预加载的时候,有些人是把所以 css 都预加载了,以便于解决 hash 出现在 css 文件的名字里,导致预加载了一些首屏用不到的 css。这个插件优化了这个问题。 4、目前支持 vite>=4 , node>=16.20.2; 5、如果您的环境支持 node>=18.20,建议使用 1.1.2 版本。 --- 1、This is a CSS preloading plugin designed for Vite. 2、Its principle is to read the CSS links from the HTML files of your build after the packaging process and generate the corresponding preload links for preloading them in advance. 3、Since Vite automatically injects some CSS links into the HTML, some people preload all CSS to solve the problem of hashes appearing in CSS filenames, which could lead to preloading unnecessary CSS files that aren't used on the first screen. This plugin optimizes that issue. 4、only support : vite>=4 , node>=16.20.2; 5、If your env support node>=18.20,i wish you can use v1.1.2 ```js // eg: 使用案例: import preloadCss from "vite-css-preload-plugin"; export default defineConfig({ plugins: [preloadCss()] }); ```