my-web-injector
v0.0.2
Published
A web component injector for static HTML/CSS/JS
Downloads
230
Maintainers
Readme
my-web-injector
一个可将静态 HTML/CSS/JS 组件动态注入到任意网页的 NPM 包。
发布到私有NPM
# 登录私有仓库
npm login --registry=https://your-private-registry.com/npm/
# 发布
npm publish
API
inject(options)
注入组件到页面。
参数:
options.containerId (string, 可选): 自定义容器 ID
options.replaceExisting (boolean, 默认 true): 是否替换已存在的实例
返回:控制句柄对象
cleanup() //手动清理组件。安装
npm install my-web-injector
基本用法
import inject from 'my-web-injector'
// 注入组件
const handle = inject()
高级用法
import { inject, cleanup } from 'my-web-injector'
// 注入并获取控制句柄
const handle = inject({ replaceExisting: true })
// 销毁组件
handle.destroy()
// 或
cleanup()
