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

remote-run

v0.0.16

Published

run electron via remote script

Readme

electron remote run

远程运行electron的代码

run main.js from remote url.

start demo

npm start

1. 本地 start.js

const RemoteRun = require('remote-run');

RemoteRun.host = 'http://localhost:8080/bundles/';
//server root folder,  used as the local project folder
//服务器目录,作为原项目的文件夹,把main.js  preload.js 等文件放到这里即可

RemoteRun.main();
//RemoteRun.main('main.js');
//RemoteRun.main('main.js', 'preload.js');

console.log(global.RUN_REMOTE )
//是否从远程加载本项目

把项目的各种js文件都放到 runRemote.host 目录里

建议用webpack将项目的js都打包到一个文件内

2. fix preload.js

var preloadFilePath = path.join(__dirname, 'preload.js');
// use this filepath as preload file

在本地代码中,使用RemoteRun.main('main.js', 'preload.js'); 用preloadFilePath文件路径,替换以前设置preload的地方

其他

  RemoteRun.run('abc.js');
  //运行 call script: http://localhost:8080/bundles/abc.js

  const requireX = RemoteRun.runUrl;
  requireX('http://www.xxx.com/someone.js')

  RemoteRun.preload();
  RemoteRun.preload('preload.js');
  //下载preload.js

  RemoteRun.getFile('abc.jpg');
  //下载 http://localhost:8080/bundles/abc.jpg

  RemoteRun.download('abc123.jpg', url);

发布 与 测试

start.js 如上 main.js 正常写, 然后复制到服务器上 preload.js 正常写, 然后复制到服务器上

{
  "name": "RemoteRun",
  "version": "1.0.4",
  "main": "start.js",
  "scripts": {
    "start": "electron .",
    "dev": "electron main.js dev",
    "webpack": "webpack --config webpack.config.js",
}

开发时: npm run dev 启动远程: npm start

其他:

在渲染层调用隐藏的主线程的函数

const {MainMethods, PreloadExpose, proxy} = require('remote-run');


//【1.主进程】,声明哪些函数需要暴露
var callList = {
  mainVersion:()=>{},
  hideFunc:()=>{}
}
MainMethods.listen(callList);


//在【2. preload.js】中
//需要暴露的主进程的函数
var minicall = ['mainVersion'];
//需要暴露的preload内的函数
var preloadObject = ['localMethod':()=>{}];

//mainVersion, localMethod 都会直接暴露给渲染层

var MainObj = new PreloadExpose(minicall);
MainObj.addon(preloadObject);

MainObj.expose('MAIN'); //定义渲染层代理人对象为MAIN,
//mainVersion, localMethod 都会直接暴露给渲染层


//MainObj.expose('MAIN', true); //直接暴露全部主进程的函数给MAIN
//mainVersion, localMethod,hideFunc 全部都会直接暴露给渲染层


//在【3.渲染层】:
//如果MAIN内有隐藏函数(preload没声明暴露),可以用MAINx作为代理访问到主进程
const MAINx = RemoteRun.proxy(MAIN);
MAIN.hideFunc(); //报错,函数不存在
MAINx.hideFunc(); //正常 (堆栈内无法查看是否有该函数,运行后才知道)

MAINx 则可以调用任何 MAIN.callMain('method', args) 的函数。

举例: MAINx.hello(args); 实则是调用的 MAIN.callMain('hello', args) 的函数。

使用说明(仅渲染进程需要)

如果在 渲染进程使用,请在打包配置中添加:

Webpack

externals: {
  electron: "commonjs electron"
}