mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
chore(core): monorepo, esm targeting, improved management (#8707)
This commit is contained in:
57
packages/webpack/plugins/WatchStateLoggerPlugin.ts
Normal file
57
packages/webpack/plugins/WatchStateLoggerPlugin.ts
Normal file
@ -0,0 +1,57 @@
|
||||
export enum messages {
|
||||
compilationComplete = 'Webpack compilation complete.',
|
||||
startWatching = 'Webpack compilation complete. Watching for file changes.',
|
||||
changeDetected = 'File change detected. Starting incremental webpack compilation...',
|
||||
}
|
||||
|
||||
/**
|
||||
* This little plugin will report the webpack state through the console.
|
||||
* So the {N} CLI can get some idea when compilation completes.
|
||||
*/
|
||||
export class WatchStateLoggerPlugin {
|
||||
isRunningWatching: boolean;
|
||||
apply(compiler) {
|
||||
const plugin = this;
|
||||
compiler.hooks.watchRun.tapAsync('WatchStateLoggerPlugin', function (compiler, callback) {
|
||||
plugin.isRunningWatching = true;
|
||||
if (plugin.isRunningWatching) {
|
||||
console.log(messages.changeDetected);
|
||||
}
|
||||
process.send && process.send(messages.changeDetected, (error) => null);
|
||||
callback();
|
||||
});
|
||||
compiler.hooks.afterEmit.tapAsync('WatchStateLoggerPlugin', function (compilation, callback) {
|
||||
callback();
|
||||
|
||||
if (plugin.isRunningWatching) {
|
||||
console.log(messages.startWatching);
|
||||
} else {
|
||||
console.log(messages.compilationComplete);
|
||||
}
|
||||
|
||||
const emittedFiles = Object.keys(compilation.assets).filter((assetKey) => compilation.assets[assetKey].emitted);
|
||||
|
||||
const chunkFiles = getChunkFiles(compilation);
|
||||
process.send && process.send(messages.compilationComplete, (error) => null);
|
||||
// Send emitted files so they can be LiveSynced if need be
|
||||
process.send && process.send({ emittedFiles, chunkFiles, hash: compilation.hash }, (error) => null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getChunkFiles(compilation) {
|
||||
const chunkFiles = [];
|
||||
try {
|
||||
compilation.chunks.forEach((chunk) => {
|
||||
chunk.files.forEach((file) => {
|
||||
if (file.indexOf('hot-update') === -1) {
|
||||
chunkFiles.push(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('Warning: Unable to find chunk files.');
|
||||
}
|
||||
|
||||
return chunkFiles;
|
||||
}
|
Reference in New Issue
Block a user