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

xgplayer-service-miniprogram

v0.6.0

Published

video player service for byted cloud (miniprogram version)

Downloads

66

Readme

#点播视频地址获取SDK(微信小程序版本)

小程序npm发包约束

小程序支持的第三方npm存在诸多约束:

  • npm 包要求根目录下必须有构建文件生成目录(默认为 miniprogram_dist 目录),此目录可以通过在 package.json 文件中新增一个 miniprogram 字段来指定,比如:
{
  "name": "miniprogram-custom-component",
  "version": "1.0.0",
  "description": "",
  "miniprogram": "dist",
  "devDependencies": {},
  "dependencies": {}
}
  • 小程序 npm 包里只有构建文件生成目录会被算入小程序包的占用空间,上传小程序代码时也只会上传该目录的代码。如果小程序 npm 包有一些测试、构建相关的代码请放到构建文件生成目录外。另外也可以使用.npmignore文件来避免将一些非业务代码文件发布到 npm 中。

  • 测试、构建相关的依赖请放入 devDependencies 字段中避免被一起打包到小程序包中。

  • ⚠️不支持依赖 nodejs 的内置库,比如 http, axios等等,替代策略可以是自己封装📦一个基于微信小程序内部http请求的api(wx.request)的想网络请求轮子,或者使用 flyio 支持度,版本兼容行都挺好

  • 微信小程序的环境(jscore),JsCore是一个没有窗口对象的环境, window, XmlHttpRequest等不能使用

使用指南

  1. 安装npm包
npm install xgplayer-service-miniprogram --production

PS: 该安装目录可以是 根目录下的各个子目录,比如dist目录, 但不允许 node_modules 在小程序根目录外。 如果选择的安装目录不存在node_modules文件夹, 可以自建,或者先执行一遍 npm init 命令(否则后面开发者工具会报,不存在构建的npm包的错误)
为兼容不同的开发者工具版本,使用 --production 最好

  1. 构建npm包 打开开发者工具菜单的工具栏,选择-->构建npm
    如果报错,则第一步存在问题,查明原因再试

  2. 在开发者工具 详情栏 勾选 '使用npm模块'

  3. 项目中引入使用构建的npm

const myPackage = require('xgplayer-service-miniprogram')
const service = myPackage()

service.url(token)
      .then(res => {
        console.log(res)
        // 业务todo
      })
      .catch(err => {
        console.log(err)
      })

支持情况

原生小程序,mpvue框架 按照正常步骤是无异常的,wepy框架下需要正确使用构建的npm包路径,可能原因是wepy打包第三方npm包的方式不同,构建时会发现存在miniprogram_npm和npm两个文件夹,npm中的包是全局可用的,所以可以将miniprogram_npm中需要的包复制到npm文件夹即可。