diff --git a/scripts/devRunner.js b/scripts/devRunner.js index 89da976b..98f3fd3b 100644 --- a/scripts/devRunner.js +++ b/scripts/devRunner.js @@ -63,43 +63,39 @@ async function restartElectron () { if (!manualRestart) process.exit(0); }); } +function startWorkers () { + const compiler = webpack(workersConfig); + const { name } = compiler; -function startMain () { - const webpackSetup = webpack([mainConfig, workersConfig]); - - webpackSetup.compilers.forEach((compiler) => { - const { name } = compiler; - - switch (name) { - case 'workers': - compiler.hooks.afterEmit.tap('afterEmit', async () => { - console.log(chalk.gray(`\nCompiled ${name} script!`)); - console.log( - chalk.gray(`\nWatching file changes for ${name} script...`) - ); - }); - break; - case 'main': - default: - compiler.hooks.afterEmit.tap('afterEmit', async () => { - console.log(chalk.gray(`\nCompiled ${name} script!`)); - - manualRestart = true; - await restartElectron(); - - setTimeout(() => { - manualRestart = false; - }, 2500); - - console.log( - chalk.gray(`\nWatching file changes for ${name} script...`) - ); - }); - break; - } + compiler.hooks.afterEmit.tap('afterEmit', () => { + console.log(chalk.gray(`\nCompiled ${name} script!`)); + console.log(chalk.gray(`\nWatching file changes for ${name} script...`)); }); - webpackSetup.watch({ aggregateTimeout: 500 }, err => { + compiler.watch({ aggregateTimeout: 500 }, err => { + if (err) console.error(chalk.red(err)); + }); +} + +function startMain () { + const compiler = webpack(mainConfig); + const { name } = compiler; + + compiler.hooks.afterEmit.tap('afterEmit', async () => { + console.log(chalk.gray(`\nCompiled ${name} script!`)); + + manualRestart = true; + await restartElectron(); + startWorkers(); + + setTimeout(() => { + manualRestart = false; + }, 2500); + + console.log(chalk.gray(`\nWatching file changes for ${name} script...`)); + }); + + compiler.watch({ aggregateTimeout: 500 }, err => { if (err) console.error(chalk.red(err)); }); } diff --git a/src/main/ipc-handlers/schema.ts b/src/main/ipc-handlers/schema.ts index ab84bb8c..3cc012c7 100644 --- a/src/main/ipc-handlers/schema.ts +++ b/src/main/ipc-handlers/schema.ts @@ -235,7 +235,9 @@ export default (connections: {[key: string]: antares.Client}) => { } // Init exporter thread - exporter = new Worker(isDevelopment ? './dist/exporter.js' : './exporter.js'); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + exporter = new Worker(new URL('../workers/exporter', import.meta.url)); exporter.postMessage({ type: 'init', @@ -255,18 +257,18 @@ export default (connections: {[key: string]: antares.Client}) => { break; case 'end': setTimeout(() => { // Ensures that writing thread has finished - exporter.terminate(); + exporter?.terminate(); exporter = null; }, 2000); resolve({ status: 'success', response: payload }); break; case 'cancel': - exporter.terminate(); + exporter?.terminate(); exporter = null; resolve({ status: 'error', response: 'Operation cancelled' }); break; case 'error': - exporter.terminate(); + exporter?.terminate(); exporter = null; resolve({ status: 'error', response: payload }); break; diff --git a/webpack.main.config.js b/webpack.main.config.js index c95c1fc0..e0505418 100644 --- a/webpack.main.config.js +++ b/webpack.main.config.js @@ -19,7 +19,15 @@ module.exports = { // Main output: { libraryTarget: 'commonjs2', path: path.join(__dirname, 'dist'), - filename: '[name].js' + filename: '[name].js', + assetModuleFilename: (pathData) => { + const { filename } = pathData; + + if (filename.endsWith('.ts')) + return '[name].js'; + else + return '[name][ext]'; + } }, node: { global: true,