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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@haoxh/single-page

v1.0.0

Published

sigle page

Readme

sigle page

  • 具有单页面功能的多页面应用
  • 独立的前端路由功能,不需服务器配置
  • 框架代码只有4KB(引入的实际代码)
  • oop 编程模式开发
  • 完整的页面生命周期钩子函数
  • css 将内联到html中,刷新页面无感知
  • Service Workers 静态文件缓存

安装

npm i @haoxh/single-page -D

初始化目录

npx singlePageInit

开启

node scripts/start.js

打包

node scripts/build.js

目录

//.router.js
//自动注入 router 不需编写
import Router from '../../lib/router'
export default new Router([
    {
        path:'/home.html',
        // webpackChunkName 注释必须编写
        import: ()=> import(/*  webpackChunkName: 'home' */ '../../pages/home/index_page.js')
    },
    {
        path:'/person.html',
        import: ()=> import(/*  webpackChunkName: 'person' */ '../../pages/person/index_page.js')
    },
])
<!-- home/home.html -->
<html>
<head>
 <!-- 单页面跳转时自动设置 title -->
<title>home page</title>
</head>
<body>
    <div data-router>
       <!-- 编写的内容放在这里,包括数据模板等 -->
    </div>
</body>
</html>
// home/page_index.js
import module from '../../common/js/index'
// 引入html
import './home.html'
// css 依赖注入, 将css注入到 当前页面的 html 中
import './index.less'

// 第一个参数为对应的路由的路径
module.define('/home.html', {
    el: class {
        //第一次进入页面时触发
        constructor(router){
            // 设置初始变量
            this.state = {
                a:1
            }
        }
        // 即将进入页面时触发,上个页面还在时
        beforeMount() {}
        // 进入页面并且html渲染后触发
        mounted() {
            // 修改 this.state
            this.setState({a:2},(state)=>{
                // 这里渲染新的DOM,跳转链接功能自动绑定
                // dom.innerHTML = this.state...
            })
            let el = document.querySelector('.home')
            // 使用 this.addEventListener 离开页面自动卸载对应的事件
            this.addEventListener(el, 'scroll', (e)=>{
                // code...
            })
            // 获取 pathname 后的参数,并以对象形式返回
            let query = this.query()
            // 设置标题。默认在html title 填写了,就不用重新设置
            this.setTitle('home')
        }
        // 离开页面时触发
        destroyed() {}
    }
})