npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-auto-skeleton

v1.1.0

Published

vite web skeleton

Downloads

20

Readme

vite-plugin-auto-skeleton

这是使用Chrome扩展程序生成网页骨架屏的后续研究,研究一种通过vite插件实现骨架屏自动化的方案。

整个项目处于Demo阶段,欢迎交流。

开发文档

vite插件实现骨架屏自动化

效果预览

点击生成骨架屏

首屏访问

示例

参考example-vue示例项目,该项目使用vue+vite+unocss构建

使用步骤

首先初始化插件

import { SkeletonPlaceholderPlugin, SkeletonApiPlugin } from "vite-plugin-auto-skeleton/vite"

export default defineConfig({
  plugins: [
    SkeletonPlaceholderPlugin(),
    vue(),
    SkeletonApiPlugin(),
  ],
  build: {
    cssCodeSplit: false
  }
})

然后填写占位符,对于首屏渲染的骨架屏

<div id="app">__SKELETON_CONTENT__</div>

对于组件内的骨架屏

<!--其中占位符格式为`__SKELETON_${data-skeleton-root}_CONTENT__`-->
<script setup lang="ts">
  import { ref, onMounted } from "vue";
  const loading = ref(true)
  onMounted(() => {
    setTimeout(() => {
      loading.value = false
    }, 1000)
  })
</script>

<template>
  <div>
    <div v-if="loading">__SKELETON_DEMO_CONTENT__</div>
    <div data-skeleton-root="DEMO" v-else>
      <h1>标题</h1>
      <p>内容内容内容</p>
    </div>
  </div>
</template>

接着初始化客户端触发器,同时向页面插入一个可以点击生成骨架屏的按钮


import { initInject } from 'vite-plugin-auto-skeleton/client'
import 'vite-plugin-auto-skeleton/skeleton.css' // 内置的骨架屏样式,可以自己重写

createApp(App).use(router).mount('#app')

// 开发环境下才注入
if (import.meta.env.DEV) {
  setTimeout(initInject)
}

点击触发器,自动将当前页面转换成骨架屏,刷新页面即可看见效果,后续正常打包部署即可。

注意事项

由于复用了大部分的原始HTML节点,对应节点的样式类,需要全局可访问,因为vue scoped等样式暂时不支持,该方案目前测试在原子类等全局UI中表现更好。