Skip to content

Commit

Permalink
Copy updated static file on change
Browse files Browse the repository at this point in the history
  • Loading branch information
Deluze committed May 25, 2022
1 parent 1a6df7a commit 4f3d845
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions scripts/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ function restartElectron() {
startElectron();
}

function copyStaticFiles() {
copy('static');
}

/*
The working dir of Electron is build/main instead of src/main because of TS.
tsc does not copy static files, so copy them over manually for dev server.
*/
function copy(path) {
FileSystem.cpSync(
Path.join(__dirname, '..', 'src', 'main', path),
Path.join(__dirname, '..', 'build', 'main', path),
{ recursive: true }
);
}

async function start() {
console.log(`${Chalk.greenBright('=======================================')}`);
console.log(`${Chalk.greenBright('Starting Electron + Vite Dev Server...')}`);
Expand All @@ -68,18 +84,17 @@ async function start() {
const devServer = await startRenderer();
rendererPort = devServer.config.server.port;

FileSystem.cpSync(
Path.join(__dirname, '..', 'src', 'main', 'static'),
Path.join(__dirname, '..', 'build', 'main', 'static'),
{ recursive: true }
);

copyStaticFiles();
startElectron();

const path = Path.join(__dirname, '..', 'src', 'main');
Chokidar.watch(path, {
cwd: path,
}).on('change', (path) => {
if (path.startsWith(Path.join('static', '/'))) {
copy(path);
}

console.log(Chalk.blueBright(`[electron] `) + `Change in ${path}. reloading... 🚀`);

restartElectron();
Expand Down

0 comments on commit 4f3d845

Please sign in to comment.