Created
November 26, 2025 06:39
-
-
Save suveshmoza/72b10735bcdba99c619680c07dce4038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import net from 'node:net' | |
| import path from 'node:path' | |
| import process from 'node:process' | |
| import { defineConfig } from 'wxt' | |
| // Check if a port is available | |
| function isPortAvailable(port: number, host: string): Promise<boolean> { | |
| return new Promise((resolve) => { | |
| const server = net.createServer() | |
| server.once('error', () => resolve(false)) | |
| server.once('listening', () => { | |
| server.close() | |
| resolve(true) | |
| }) | |
| server.listen(port, host) | |
| }) | |
| } | |
| // Find next available port starting from a given port | |
| async function findAvailablePort(startPort: number, host: string, maxAttempts = 50): Promise<number> { | |
| for (let port = startPort; port < startPort + maxAttempts; port++) { | |
| if (await isPortAvailable(port, host)) { | |
| return port | |
| } | |
| } | |
| throw new Error(`No available port found between ${startPort} and ${startPort + maxAttempts}`) | |
| } | |
| // See https://wxt.dev/api/config.html | |
| export default defineConfig({ | |
| srcDir: 'src', | |
| imports: false, | |
| modules: ['@wxt-dev/module-react', '@wxt-dev/i18n/module'], | |
| manifestVersion: 3, | |
| // WXT top level alias - will be automatically synced to tsconfig.json paths and Vite alias | |
| alias: process.env.WXT_USE_LOCAL_PACKAGES === 'true' | |
| ? { | |
| '@read-frog/definitions': path.resolve(__dirname, '../read-frog-monorepo/packages/definitions/src'), | |
| '@read-frog/api-contract': path.resolve(__dirname, '../read-frog-monorepo/packages/api-contract/src'), | |
| } | |
| : {}, | |
| manifest: ({ mode, browser }) => ({ | |
| name: '__MSG_extName__', | |
| description: '__MSG_extDescription__', | |
| default_locale: 'en', | |
| permissions: ['storage', 'tabs', 'alarms', 'cookies'], | |
| host_permissions: | |
| mode === 'development' | |
| ? [ | |
| 'http://localhost:*/*', // For local backend (dev:local) | |
| 'https://*.readfrog.app/*', // For prod backend (dev) | |
| 'https://readfrog.app/*', // For prod backend (dev) | |
| ] | |
| : [ | |
| 'https://*.readfrog.app/*', | |
| 'https://readfrog.app/*', // Include both www and non-www versions | |
| ], | |
| // Firefox-specific settings for MV3 | |
| ...(browser === 'firefox' && { | |
| browser_specific_settings: { | |
| gecko: { | |
| id: 'extension@readfrog.app', | |
| strict_min_version: '109.0', | |
| }, | |
| }, | |
| }), | |
| }), | |
| dev: { | |
| server: { | |
| // Port will be resolved dynamically in the hook below | |
| }, | |
| }, | |
| hooks: { | |
| 'config:resolved': async (wxt) => { | |
| // Only run during dev server | |
| if (wxt.config.command === 'serve' && wxt.config.dev.server) { | |
| const host = wxt.config.dev.server.host ?? 'localhost' | |
| // Find available port starting from 3333 | |
| const port = await findAvailablePort(3333, host) | |
| wxt.config.dev.server.port = port | |
| wxt.config.dev.server.origin = `http://${host}:${port}` | |
| } | |
| }, | |
| }, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment