本文介绍了最后 NPM 包输出消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道在 npm install 之后是否可以在最后打印一条日志消息?

Did anyone know if it's possible to print a log message at the very end after the npm install?

  To enable CLI tab autocompletion run:
   mypackage completion >> ~/.profile


  [email protected] node_modules/progress

  [email protected] node_modules/kew

  [email protected] node_modules/adm-zip

  [email protected] node_modules/request-progress
  └── [email protected]
  ....

但是我想在依赖下载后给一个消息,例如:

But I want to give a message after the dependency download, e.g:

  [email protected] node_modules/progress

  [email protected] node_modules/kew

  [email protected] node_modules/adm-zip

  [email protected] node_modules/request-progress
  └── [email protected]
  To enable CLI tab autocompletion run:
   mypackage completion >> ~/.profile

我通过安装后脚本尝试过,但不起作用

I tried it via a post installation script, but doesn't work

推荐答案

来自 关于 的 npm 文档"scripts" 它指出您可以使用与命令链接的 "postinstall"(或只是 "install")在软件包已安装...

From the npm documentation on "scripts" it states you can use the "postinstall" (or just "install") linked up with a command to run after the package has installed...

既然你说你已经尝试过这个,但在你的问题中没有给出关于如何做的背景,让我来引导你完成整个过程......

Since you say you already attempted this, but gave no context in your question on how, let me just walk you through the process...

例如,假设这是在您的 package.json 中:

For example, say this were in your package.json:

{
  ...
  "scripts": {
    "postinstall": "node postinstall.js"
  }
  ...
}

然后,在您的项目目录中,您可以创建一个 postintall.js 脚本,并将其放入其中:

Then, in your project directory, you can create a postintall.js script, and put this in it:

console.log(
  "To enable CLI tab autocompletion run:\n" +
  "mypackage completion >> ~/.profile"
);

这篇关于最后 NPM 包输出消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:45