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

@inventorjs/sdk-loader

v0.0.13

Published

SDK Loader

Downloads

15

Readme

@inventorjs/sdk-loader

概述

基于 systemjs 实现的通用 sdk 加载器,可实现根据 sdk 资源配置,加载 sdk ,返回 sdk 模块,支持 js, chunks 和 css.

功能列表

  • 基于 systemjs 实现模块模块管理,支持 js(支持 system 格式) json css 类型的模块
  • systemjs 加载 json 和 css 需要用到 fetch,支持自动加载 fetch polyfill
  • css 模块加载后返回 CSSStyleSheet 对象列表,用户可自定义如何使用
  • 支持多 sdk 并发加载,需要考虑最大并发数可能会影响性能
  • 支持直接传入 sdkConfigs 配置对象 或 传入 sdkConfigs 配置对象的远程 json 地址,可自动加载
  • 支持自定义加载超时时间,默认 10s,超时后会抛出错误
  • 支持 webpack / rollup 打包的 systemjs 模块,可配置优先加载 chunk(webpack 的 SplitChunks 对 systemjs 兼容不好)

兼容性:不兼容 IE,Edge 以上没问题

副作用:systemjs 会在全局注入 System 全局变量,用于模块管理

注意:js 模块需要打包成 system 格式,webpack配置 rollup配置,推荐使用 rollup

代码示例

  import { loadSdk } from './sdk-loader'
  import ReactDOM from 'react-dom'

  loadSdk({
    sdkConfigs: {
      testSdk: {
        manifest: {
          entry: 'http://localhost:3000/dist/index.js',
          chunks: ['http://localhost:3000/dist/react-7138bc01.js'],
          css: ['http://localhost:3000/dist/style.css'],
        },
        version: 'v1',
      },
    },
    options: {
      timeout: 15000,
      chunksPreload: true, // 默认为 false,是否预加载 chunks,webpack 构建的 chunks 请传 true
      cssEffect: true, // 默认为 false,加载完 css 是否在页面生效,优先使用 adoptedStyleSheets,若不支持,降级为 link
      documentRoot: document, // 默认为 document, css 生效的文档对象,可传 shadowDom Root
    }
  }).then(({ testSdk: { entry, chunks, css } }) => {
    console.log(entry, chunks, css)
  })