ngrok-rsbuild-plugin
April 9, 2025 ยท View on GitHub
๐ Expose your rsbuild dev server over the internet via ngrok โ built for use with the LynxJS Native App Framework.
This plugin creates an ngrok tunnel for your dev server, sets the correct assetPrefix for remote access, and optionally integrates with @lynx-js/qrcode-rsbuild-plugin to generate a QR code for fast mobile testing.
โ ๏ธ Disclaimer: This README and plugin were generated and written with the help of AI. It may contain inaccuracies.
I'm not affiliated with LynxJS or its maintainers โ this was built independently for use with the LynxJS ecosystem.๐ ๏ธ Pull requests are welcome! If you notice something broken or unclear, feel free to contribute!
Features
- ๐ Automatically exposes your dev server using
ngrok - ๐ Injects
assetPrefixintodevconfig for remote asset loading - ๐ฑ (Optional) Displays a QR code with your public ngrok URL for mobile devices
- ๐ Logs activity to
logs.txtfor debugging
Installation
npm install ngrok ngrok-rsbuild-plugin @lynx-js/qrcode-rsbuild-plugin --save-dev
Setup
Step 1: Add NGROK_TOKEN to your .env
NGROK_TOKEN=your-ngrok-authtoken
Step 2: Use the plugin in your rsbuild config
// rsbuild.config.ts or index.ts
import { pluginNgrok, setServer } from './ngrok-rsbuild-plugin'
export default {
plugins: [pluginNgrok()],
async setup() {
const config = await setServer({
host: 'localhost',
port: 3000,
});
return config;
}
}
API
setServer({ host, port })
Returns modified server and dev config with an updated assetPrefix.
pluginNgrok(options?)
Initializes the plugin and exposes the ngrok URL via the rsbuild API. Optionally accepts:
{
schema?: (url: string) => any // defaults to { http: url }
}
Notes
- You must have a valid
NGROK_TOKENset in your.envfile. - The plugin writes logs to
logs.txtin the project root. - The
ngrokURL is exposed viaapi.expose('lynx:rsbuild:ngrok', { ngrok_url }). - This module uses
custompatchto patch@lynx-js/rspeedy@^0.9.0, preventing it from automatically appending a port number to the ngrok URL. Make surecustompatchis installed and patched correctly if you encounter any URL formatting issues.
License
MIT