Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@kwai-explore/picture.vue
Advanced tools
用于配合图片压缩插件,展示多种图片格式的 Picture 组件。
pnpm add @kwai-explore/picture.vue
Tip: 以前用的是 image-prest 现在使用 vite-imagetools 插件
建议配合 vite-imagetools 使用
pnpm add -D vite-imagetools
配置插件:修改 vite.config.ts
import { imagetools } from 'vite-imagetools';
export default defineConfig({
plugins: [
// ...
imagetools({
defaultDirectives: (url) => {
if (url.searchParams.get('preset') === 'modern') {
return new URLSearchParams({
format: 'avif;webp;' + url.pathname.substring(url.pathname.lastIndexOf('.') + 1),
as: 'picture'
});
}
return new URLSearchParams();
},
})
],
});
vite-env.d.ts
这里的类型就是图片转换插件的输出类型,Picture组件已经定义好了
这一步是避免ts报错
declare module '*?preset=modern' {
const src: import('vite-imagetools').Picture;
export default src;
}
<script setup lang="ts">
import Picture from '@kwai-explore/picture.vue';
import examplePic from './components/example.jpg?preset=modern';
</script>
<template>
<Picture :src="examplePic" placeholder="color" />
</template>
Picture 组件接受的属性跟 img
相同,唯一的例外是 src
接收一个对象,如:
{ // vite-imagetools 生成的图片对象
img: {src: '/@imagetools/19b8f0e7a78', w: 5304, h: 7952}
sources: {avif: '/@imagetools/6165531 5304w', webp: '/@imagetools/58dbfda 5304w'}
}
根据上面配置好 vite-imagetools
后,import 图片时后面加一个query:?preset=modern
,产出的数据就是这样的。
type PictureProp = {
src: Picture | FallbackPictureOption;
/** color 会展示一个渐变色块的 loading 效果,加上 fade-in 的加载成功的渐变 */
placeholder: 'empty' | 'color';
} & Omit<ImgHTMLAttributes, 'src'>
'vue/no-restricted-html-elements': [
'warn',
{
element: 'img',
message: 'Prefer use of our @kwai-explore/picture.vue component',
},
],
开发环境(vite dev
) 初次请求图片资源时需要进行格式转换,图片的加载时间比较长。
生产环境(vite build
) 会把需要的图片格式都构建出来。
vue >= 3.3
FAQs
用于配合图片压缩插件,展示多种图片格式的 Picture 组件。
We found that @kwai-explore/picture.vue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.