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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spark-view/spark-page-config

v0.3.1

Published

SPARK 页面配置层 - 支持本地/远程配置加载、动态路由注册、配置缓存和验证

Downloads

991

Readme

@spark-view/spark-page-config

SPARK 页面配置层 - 支持本地/远程配置加载、动态路由和配置验证

TypeScript Vue

特性

  • 多源加载 - 本地(SPA)/远程(API)/混合模式
  • 动态路由 - 运行时注册路由,支持懒加载
  • 配置缓存 - 内存缓存,可配置过期时间
  • 配置验证 - Schema 验证,确保配置正确
  • 脚本沙箱 - 安全执行页面脚本
  • 热更新 - 支持配置刷新

安装

pnpm add @spark-view/spark-page-config

快速开始

1. 配置文件结构

public/pages-config/
  routes.json           # 路由配置
  <pageId>/
      rule.json         # 页面规则(组件树)
      pagedata.json     # 页面数据
      script.js         # 页面脚本(可选)

2. 路由配置 (routes.json)

[
  {
    "path": "/home",
    "name": "home",
    "pageId": "home",
    "meta": {
      "title": "首页",
      "icon": "",
      "requiresAuth": true
    }
  }
]

3. 页面规则 (rule.json)

{
  "type": "container",
  "id": "root",
  "children": [
    {
      "type": "spark-ej2-grid",
      "id": "userGrid",
      "props": {
        "dataSource": "@{dataSet.Users}"
      }
    }
  ]
}

4. 使用配置加载器

import { createConfigLoader } from '@spark-view/spark-page-config'

// 创建加载器
const loader = createConfigLoader({
  source: 'local',  // 'local' | 'remote' | 'hybrid'
  fileStorage: 'localStorage'  // 'localStorage' | 'sessionStorage' | 'memory'
})

// 加载路由配置
const routes = await loader.loadRoutes()

// 加载页面配置
const pageConfig = await loader.loadPageConfig('home')

5. 动态路由注册

import { setupDynamicRoutes } from '@spark-view/spark-page-config'
import { PageRenderer } from '@spark-view/spark-component'
import { createRouter } from 'vue-router'

const router = createRouter({ ... })

// 注册动态路由
await setupDynamicRoutes(router, loader, PageRenderer)

核心 API

ConfigLoader

配置加载器

const loader = createConfigLoader({
  source: 'local',           // 加载模式
  fileStorage: 'localStorage', // 缓存存储次层
  timeout: 10000             // 请求超时(毫秒,仅 remote 模式有效)
})

// 加载方法
await loader.loadRoutes()                    // 加载路由
await loader.loadPageConfig(pageId)          // 加载页面配置(rule + data + script + css)
await loader.loadRule(pageId)               // 加载页面规则
await loader.loadPageData(pageId)            // 加载页面数据
await loader.loadScript(pageId)             // 加载页面脚本
await loader.loadCss(pageId)                // 加载页面样式

// 缓存管理
loader.clearCache()                          // 清空缓存
loader.getCacheStats()                       // 缓存统计

配置验证

import { validateRouteConfig, validateRuleConfig } from '@spark-view/spark-page-config'

// 验证路由配置(返回错误数组,空数组表示有效)
const routeErrors = validateRouteConfig(routeConfig)
if (routeErrors.length > 0) {
  console.error('路由配置无效:', routeErrors)
}

// 验证页面规则
const ruleErrors = validateRuleConfig(ruleConfig)
if (ruleErrors.length > 0) {
  console.error('规则配置无效:', ruleErrors)
}

与 L1 (spark-app) 集成

本包依赖 spark-app 提供的基础设施:

  • Logger - 使用 pageLoggerrouterLogger
  • 符号常量 - 使用 DefaultConfigErrorCodes
  • 错误处理 - 统一错误码和消息
  • 权限过滤 - 通过 beforeRegister 钩子集成

详细集成说明请查阅 INTEGRATION.md

API 文档

完整 API 文档请查看 API.md

依赖

{
  "@spark-view/spark-app": "workspace:*",
  "vue-router": "^4.2.0"
}

开发命令

pnpm run typecheck   # 类型检查
pnpm run test        # 运行测试
pnpm run build       # 构建包

License

MIT