Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/unsight.dev. Detect duplicate GitHub issues, areas of concern and more across related rep unsight.dev
Something went wrong. Try again.
1.2 kB · 40 lines
TypeScript
at web-ext
1234567891011121314151617181920212223242526272829303132333435363738394041// generate stub index.html files for dev entryimport { execSync } from 'node:child_process'import fs from 'node:fs/promises'import chokidar from 'chokidar'import { isDev, log, port, r } from './utils'
/** * Stub index.html to use Vite in development */async function stubIndexHtml() { const views = ['options', 'popup', 'sidepanel']
for (const view of views) { await fs.mkdir(r(`extension/dist/${view}`), { recursive: true }) let data = await fs.readFile(r(`src/${view}/index.html`), 'utf-8') data = data .replace('"./main.ts"', `"http://localhost:${port}/${view}/main.ts"`) .replace('<div id="app"></div>', '<div id="app">Vite server did not start</div>') await fs.writeFile(r(`extension/dist/${view}/index.html`), data, 'utf-8') log('PRE', `stub ${view}`) }}
function writeManifest() { execSync('npx esno ./scripts/manifest.ts', { stdio: 'inherit' })}
writeManifest()
if (isDev) { stubIndexHtml() chokidar.watch(r('src/**/*.html')) .on('change', () => { stubIndexHtml() }) chokidar.watch([r('src/manifest.ts'), r('package.json')]) .on('change', () => { writeManifest() })}