TerminalPrintPlugin.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import chalk from 'chalk';
  2. import { Compiler } from 'webpack';
  3. import WebpackDevServer from 'webpack-dev-server';
  4. const localIPv4 = WebpackDevServer.internalIPSync('v4');
  5. class TerminalPrintPlugin {
  6. constructor() {}
  7. apply(compiler: Compiler) {
  8. compiler.hooks.done.tapAsync('TerminalPrintPlugin', (stats, callback) => {
  9. const publicPath = stats.compilation.outputOptions.publicPath as string;
  10. const port = stats.compilation.options.devServer!.port as number;
  11. console.log(' App running at:');
  12. console.log(
  13. `- Local: ${chalk.cyan(`http://localhost:${port}${publicPath}`)}`
  14. );
  15. console.log(
  16. `- Network: ${chalk.cyan(`http://${localIPv4!}:${port}${publicPath}`)}`
  17. );
  18. console.log(
  19. `- 赞助打赏: ${chalk.cyan(`https://live.hsslive.cn/sponsors`)}`
  20. );
  21. console.log(
  22. `- 付费支持: ${chalk.cyan(`https://live.hsslive.cn/support`)}`
  23. );
  24. console.log(
  25. `- 欢迎PR: ${chalk.cyan(
  26. `billd-live目前只有作者一人开发,难免有不足的地方,欢迎提PR或Issue`
  27. )}`
  28. );
  29. console.log();
  30. callback();
  31. });
  32. }
  33. }
  34. export default TerminalPrintPlugin;