Files
Paradise/tgui/packages/tgui-dev-server/webpack.js
AffectedArc07 58aa86cb9f TGUI-V3 (#13310)
* I need that gitignore file

* Temp Commit - DOES NOT COMPILE

* THE SHIT WORKS

* Readme change

* Disposal Unit --> TGUI

* mmmm yes CI which may not actually work

* New GitIgnore

* ITS TGUI-NEXT BABY

* Doc update

* CI tweak

* Chmod

* And again

* *sigh*

* Lets appreciate the irony of me failing CI stages

* 0/1 --> True/False

* Fixes some update nonsense

* CI Update

* Lets try this

* What about this maybe

* NVM is hurting me

* I swear to god

* A little bit of validation in my life

* V3 BABYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

* Fixes

* Fixes NaN appearing for a few frames when UIs open

* Fixes + Crew Monitor

* Corn + Steel + Mochi Fixes

* Forgot this

* Fixes from stylemistake

* Code Change

* Adds logout proc

* Offline implications + Resizeable crew monitor

* Change locate() to locateUID()

* Change div --> box
2020-06-30 03:51:36 -04:00

55 lines
1.7 KiB
JavaScript

import { createLogger } from 'common/logging.js';
import fs from 'fs';
import { createRequire } from 'module';
import { promisify } from 'util';
import webpack from 'webpack';
import { broadcastMessage, loadSourceMaps, setupLink } from './link/server.js';
import { reloadByondCache } from './reloader.js';
import { resolveGlob } from './util.js';
const logger = createLogger('webpack');
export const getWebpackConfig = async options => {
const require = createRequire(import.meta.url);
const createConfig = await require('../tgui/webpack.config.js');
return createConfig({}, options);
};
export const setupWebpack = async config => {
logger.log('setting up');
const bundleDir = config.output.path;
// Setup link
const link = setupLink();
// Instantiate the compiler
const compiler = webpack(config);
// Clear garbage before compiling
compiler.hooks.watchRun.tapPromise('tgui-dev-server', async () => {
const files = await resolveGlob(bundleDir, './*.hot-update.*');
logger.log(`clearing garbage (${files.length} files)`);
for (let file of files) {
await promisify(fs.unlink)(file);
}
logger.log('compiling');
});
// Start reloading when it's finished
compiler.hooks.done.tap('tgui-dev-server', async stats => {
// Load source maps
await loadSourceMaps(bundleDir);
// Reload cache
await reloadByondCache(bundleDir);
// Notify all clients that update has happened
broadcastMessage(link, {
type: 'hotUpdate',
});
});
// Start watching
logger.log('watching for changes');
compiler.watch({}, (err, stats) => {
if (err) {
logger.error('compilation error', err);
return;
}
logger.log(stats.toString(config.devServer.stats));
});
};