mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: external config loading
+refactor many pieces
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import webpack from 'webpack';
|
||||
|
||||
const id = 'WatchStateLoggerPlugin';
|
||||
export enum messages {
|
||||
compilationComplete = 'Webpack compilation complete.',
|
||||
startWatching = 'Webpack compilation complete. Watching for file changes.',
|
||||
@@ -13,15 +16,20 @@ export class WatchStateLoggerPlugin {
|
||||
|
||||
apply(compiler) {
|
||||
const plugin = this;
|
||||
compiler.hooks.watchRun.tapAsync('WatchStateLoggerPlugin', function (compiler, callback) {
|
||||
|
||||
compiler.hooks.watchRun.tapAsync(id, function (compiler, callback) {
|
||||
plugin.isRunningWatching = true;
|
||||
|
||||
if (plugin.isRunningWatching) {
|
||||
console.log(messages.changeDetected);
|
||||
}
|
||||
process.send && process.send(messages.changeDetected, (error) => null);
|
||||
|
||||
notify(messages.changeDetected);
|
||||
|
||||
callback();
|
||||
});
|
||||
compiler.hooks.afterEmit.tapAsync('WatchStateLoggerPlugin', function (compilation, callback) {
|
||||
|
||||
compiler.hooks.afterEmit.tapAsync(id, function (compilation, callback) {
|
||||
callback();
|
||||
|
||||
if (plugin.isRunningWatching) {
|
||||
@@ -30,18 +38,20 @@ export class WatchStateLoggerPlugin {
|
||||
console.log(messages.compilationComplete);
|
||||
}
|
||||
|
||||
const emittedFiles = Object.keys(compilation.assets).filter((assetKey) => compilation.assets[assetKey].emitted);
|
||||
const emittedFiles = Object.keys(compilation.assets).filter(
|
||||
(assetKey) => compilation.assets[assetKey].emitted
|
||||
);
|
||||
const chunkFiles = getChunkFiles(compilation);
|
||||
|
||||
process.send && process.send(messages.compilationComplete, (error) => null);
|
||||
notify(messages.compilationComplete);
|
||||
|
||||
// Send emitted files so they can be LiveSynced if need be
|
||||
process.send && process.send({ emittedFiles, chunkFiles, hash: compilation.hash }, (error) => null);
|
||||
notify({ emittedFiles, chunkFiles, hash: compilation.hash });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getChunkFiles(compilation) {
|
||||
function getChunkFiles(compilation: webpack.Compilation) {
|
||||
const chunkFiles = [];
|
||||
try {
|
||||
compilation.chunks.forEach((chunk) => {
|
||||
@@ -57,3 +67,17 @@ function getChunkFiles(compilation) {
|
||||
|
||||
return chunkFiles;
|
||||
}
|
||||
|
||||
function notify(message: any) {
|
||||
if (!process.send) {
|
||||
return;
|
||||
}
|
||||
|
||||
process.send(message, (error) => {
|
||||
if (error) {
|
||||
console.error(`[${id}] Process Send Error: `, error);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user