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

vite-plugin-remote-module

v1.1.4

Published

Load HTTP remote module in the Vite project

Downloads

3

Readme

vite-plugin-remote-module

在vite中通过http链接加载远程模块

相关链接

使用

插件注册

// vite.config.js
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import remoteModulePlugin from 'vite-plugin-remote-module'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    remoteModulePlugin()
  ]
})

静态加载

import Demo from '@remote/http://localhost:3000/demo.vue'

异步加载

async function asyncLoadDemo() {
  const ans = await import('@remote/http://localhost:3000/demo.vue')
  compRef.value = ans.default
}

动态加载

import {loadRemoteComponent} from '@vite-plugin-remote-module';

const componentList = [
  {id: 1, name: 'demo', url: 'http://localhost:3000/demo.vue'},
  {id: 2, name: 'demo2', url: 'http://localhost:3000/demo2.vue'},
  {id: 3, name: 'demo3', url: 'http://localhost:3000/demo3.vue'},
]

async function loadComp(item) {
  const {url} = item
  compRef.value = await loadRemoteComponent(url)
}

loadComp(componentList[0])
loadComp(componentList[1])
loadComp(componentList[2])

打包

一些限制

如果是已经下载到本地的远程模块(静态加载和异步加载),按照常规打包即可

如果是动态加载的模块,需要确保远程模块已经被下载,否则在打包后可能存在找不到对应模块的情况

安全性

由于加载远程模块的原理是:将远程模块下载到本地并加载,因此请注意不要加载未信任的远程模块,这可能会造成安全问题!!

本地调试


git clone 仓库

# 安装插件依赖
npm i 

# 安装vite项目依赖
cd example && npm i 

# 启动vite
npm run dev

然后浏览器访问vite服务即可