0.0.1 • Published 4 years ago
vipu v0.0.1
Install
$ npm i vipuWhat is this?
Note: this project is WIP (work in progress) and its API will probably change.
This is a development tool combining vite + puppeteer + alice-bob designed for rapid iteration and testing of frontend solutions without having to switch to the browser. You can interop with Node using RPC which is already configured. Client side refreshes on change as usual with Vite and with a tool like onchange or nodemon you can configure the server side to refresh as well.
Example
On the server (node.js):
import { vipu } from 'vipu'
import type { Client } from './client'
export interface Server {
sayHi: ({ iam }: { iam: string }) => Promise<string>
finish: () => Promise<void>
}
export interface WindowHandle {
vipu: {
server: Server
}
}
vipu<Server, Client>(require.resolve('./client.ts')).then(
({ server, client, page, finish }) => {
server.finish = finish
server.sayHi = async ({ iam }) => `hello ${iam}`
page.on('load', async () => {
const result = await client.multiply(3, 4)
console.log('from client:', result)
// => from client: 12
})
},
)On the client:
import type { WindowHandle } from './index'
declare const window: WindowHandle
const server = window.vipu.server
;(async () => {
console.log('from server:', await server.sayHi({ iam: 'The Client' }))
// => from server: hello The Client
})()
const client = {
multiply: async (x: number, y: number) => x * y,
}
export default client
export type Client = typeof clientAPI
Table of Contents
vipu
Creates a vipu instance.
Parameters
entrystring Entry file. Must be a full path, which can be obtained usingrequire.resolve(). It can be anything Vite supports, .ts, .tsx work as well.configConfig Configuration. (optional, default{})config.rpcPassed to AliceBobagents. (optional, default{})config.viteVite configuration. Passed to vitecreateServer. (optional, default{})config.puppeteerPuppeteer launch configuration. Passed topuppeteer.launch. (optional, default{})config.infoWhether to display info messages in console. (optional, defaulttrue)config.logLog function that can be overriden. (optional, defaultvipuLog)
Contribute
All contributions are welcome!
License
MIT © 2021 stagas