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

wujie-card-sdk

v1.0.1

Published

SDK for Wujie card development to abstract environment dependencies

Downloads

241

Readme

Wujie Card SDK

该 SDK 用于帮助卡片开发者构建微前端应用,使其在工作台容器环境与本地开发环境中都能无缝运行。

安装

npm install wujie-card-sdk

使用方式(Vue)

1. 在 main.js 中初始化(推荐)

wujie-card-sdk/vue 引入 defineCard,用于自动处理 Wujie 生命周期与运行环境识别。

import { defineCard } from 'wujie-card-sdk/vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

// 本地开发使用的 Mock 数据
// 注意:mockData 模拟的是从上层工作台传入的数据。
// 仅当卡片内部逻辑必须依赖这些外部数据时,才需要在此配置 mock 数据。
const mockData = {
  theme: 'light'
}

defineCard({
  rootComponent: App,
  mockData,
  debug: true,
  // 通过 setup 安装插件(router、pinia、element-plus 等)
  setup: (app) => {
    app.use(ElementPlus)
  }
})

2. 在组件中使用上下文(App.vue

<script setup>
import { useCardContext } from 'wujie-card-sdk/vue'
import { watch, ref } from 'vue'

const { props } = useCardContext()
const sales = ref(0)

// 获取主应用下发的数据(或本地开发时的 mockData)
watch(props, () => {
  if (props.data) {
    sales.value = props.data.sales
  }
}, { immediate: true, deep: true })
</script>

功能特性

  • 生命周期管理:自动处理 window.__WUJIE_MOUNTwindow.__WUJIE_UNMOUNT
  • 环境自适应:自动识别是否处于 Wujie 环境。
  • Mock 数据:本地运行时可提供 mock 数据。

TypeScript 支持

SDK 内置 TypeScript 类型定义。请确保你的 tsconfig.json 中包含该 SDK 的类型:

{
  "compilerOptions": {
    "types": ["wujie-card-sdk"]
  }
}

xw 兼容用法

SDK 提供 xw 兼容层,支持与历史 xw.js 调用方式一致的 API。可在组件中通过上下文获取 host 来调用。

<script setup>
import { useCardContext } from 'wujie-card-sdk/vue'

const { host } = useCardContext()

host.xw('getUserInfo', {
  success: (res) => {
    console.log('用户信息', res)
  },
  fail: (msg) => {
    console.error('获取用户信息失败', msg)
  }
})

host.xw('getMainConfig', {
  success: (res) => {
    console.log('主应用配置', res)
  }
})

host.xw('getCpnConfig', {
  params: { name: 'your-component-name' },
  success: (conf) => {
    console.log('组件配置', conf)
  }
})

host.xw('openAlert', {
  params: { title: '提示', message: '内容文本' }
})

host.xw('openNewTab', {
  params: { title: '新标签', path: '/your/path', query: { id: '1' } }
})

host.xw('openWindow', {
  params: { url: 'https://example.com' }
})

host.xw('jump', {
  params: { path: '/your/path', query: { id: '1' } }
})

host.xw('updateTabName', {
  params: { name: '新的标题' }
})

host.xw('close')
</script>