mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
chore: clean up old WatchStateLoggerPlugin
This commit is contained in:
@ -7,7 +7,6 @@ import FilterWarningsPlugin from 'webpack-filter-warnings-plugin';
|
|||||||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
||||||
import TerserPlugin from 'terser-webpack-plugin';
|
import TerserPlugin from 'terser-webpack-plugin';
|
||||||
|
|
||||||
// import { WatchStateLoggerPlugin } from '../plugins/WatchStateLoggerPlugin';
|
|
||||||
import { getProjectFilePath, getProjectRootPath } from '../helpers/project';
|
import { getProjectFilePath, getProjectRootPath } from '../helpers/project';
|
||||||
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
||||||
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
||||||
@ -308,8 +307,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
|
|
||||||
applyCopyRules(config);
|
applyCopyRules(config);
|
||||||
|
|
||||||
// add the WatchStateLogger plugin used to notify the CLI of build state
|
|
||||||
// config.plugin('WatchStateLoggerPlugin').use(WatchStateLoggerPlugin);
|
|
||||||
config.plugin('WatchStatePlugin').use(WatchStatePlugin);
|
config.plugin('WatchStatePlugin').use(WatchStatePlugin);
|
||||||
|
|
||||||
config.when(env.hmr, (config) => {
|
config.when(env.hmr, (config) => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
// This is a runtime module - included by nativescript-hot-loader
|
// This is a runtime module - included by nativescript-hot-loader
|
||||||
// this file should not include external dependencies
|
// this file should not include external dependencies
|
||||||
|
// todo: add verbose logs when enabled
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
|
@ -4,10 +4,9 @@ import { INativeScriptPlatform } from "../helpers/platform";
|
|||||||
import { getProjectRootPath } from "../helpers/project";
|
import { getProjectRootPath } from "../helpers/project";
|
||||||
|
|
||||||
function sanitizeName(appName: string): string {
|
function sanitizeName(appName: string): string {
|
||||||
const sanitizedName = appName.split("").filter((c) =>
|
return appName.split("").filter((c) =>
|
||||||
/[a-zA-Z0-9]/.test(c)
|
/[a-zA-Z0-9]/.test(c)
|
||||||
).join("");
|
).join("");
|
||||||
return sanitizedName;
|
|
||||||
}
|
}
|
||||||
function getDistPath() {
|
function getDistPath() {
|
||||||
const appName = sanitizeName(basename(getProjectRootPath()));
|
const appName = sanitizeName(basename(getProjectRootPath()));
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
import webpack from 'webpack';
|
|
||||||
|
|
||||||
const id = 'WatchStateLoggerPlugin';
|
|
||||||
|
|
||||||
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.
|
|
||||||
* @deprecated todo: remove soon
|
|
||||||
*/
|
|
||||||
export class WatchStateLoggerPlugin {
|
|
||||||
isRunningWatching: boolean;
|
|
||||||
|
|
||||||
apply(compiler) {
|
|
||||||
const plugin = this;
|
|
||||||
|
|
||||||
compiler.hooks.watchRun.tapAsync(id, function (compiler, callback) {
|
|
||||||
plugin.isRunningWatching = true;
|
|
||||||
|
|
||||||
if (plugin.isRunningWatching) {
|
|
||||||
console.log(messages.changeDetected);
|
|
||||||
}
|
|
||||||
|
|
||||||
notify(messages.changeDetected);
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
|
|
||||||
compiler.hooks.afterEmit.tapAsync(id, function (compilation, callback) {
|
|
||||||
callback();
|
|
||||||
|
|
||||||
if (plugin.isRunningWatching) {
|
|
||||||
console.log(messages.startWatching);
|
|
||||||
} else {
|
|
||||||
console.log(messages.compilationComplete);
|
|
||||||
}
|
|
||||||
|
|
||||||
const emittedFiles = Array.from(compilation.emittedAssets);
|
|
||||||
const chunkFiles = getChunkFiles(compilation);
|
|
||||||
|
|
||||||
notify(messages.compilationComplete);
|
|
||||||
|
|
||||||
// Send emitted files so they can be LiveSynced if need be
|
|
||||||
notify({ emittedFiles, chunkFiles, hash: compilation.hash });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChunkFiles(compilation: webpack.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
function notify(message: any) {
|
|
||||||
if (!process.send) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
process.send(message, (error) => {
|
|
||||||
if (error) {
|
|
||||||
console.error(`[${id}] Process Send Error: `, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
@ -9,8 +9,8 @@ export enum messages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This little plugin will report the webpack state through the console.
|
* This little plugin will report the webpack state through the console
|
||||||
* So the {N} CLI can get some idea when compilation completes.
|
* and send status updates through IPC to the {N} CLI.
|
||||||
*/
|
*/
|
||||||
export class WatchStatePlugin {
|
export class WatchStatePlugin {
|
||||||
apply(compiler: any) {
|
apply(compiler: any) {
|
||||||
|
Reference in New Issue
Block a user