@fkn/vite-plugin
v0.2.0
Published
Vite plugin that aliases Node builtins (fs, net, dgram) to @fkn/lib's browser polyfills
Downloads
80
Readme
@fkn/vite-plugin
Node-in-the-browser for FKN apps. One plugin aliases the Node builtins to the FKN polyfills, so you write
fs / net / dgram exactly as you would in Node and it works in the browser, backed by the FKN platform
(networked storage over OPFS + cloud, real TCP/UDP sockets through WebVPN).
// vite.config.ts
import { defineConfig } from 'vite'
import { fkn } from '@fkn/vite-plugin'
export default defineConfig({
plugins: [fkn()],
})// anywhere in your app
import fs from 'fs'
import net from 'net'
fs.writeFileSync('/save/state.json', JSON.stringify(state))
const socket = net.connect(443, 'example.com')It:
- aliases
fs+fs/promisesto@fkn/fs-polyfill,netto@webvpn/net,dgramto@webvpn/dgram(and theirnode:forms), with exact-match resolution so a package likefs-extrais left alone; - falls back to
node-stdlib-browserfor every other Node builtin (stream,events,buffer, …); - provides the
Buffer/process/globalshims the polyfills rely on.
Disable any backend you don't want aliased:
fkn({ net: false, dgram: false }) // fs only