跳到主要内容
CNode

请教一下怎样在npm install 之后执行npm scripts里面的内容?

问答
Ffernandou发布于 10 年前最后回复 10 年前
672080

如题,看到很多开源项目都是在npm install可以启动项目,所以想知道一下怎么实现的?

查看回复

回复 (6)

H
hezhongfeng#610 年前
引用 luoyjx@hezhongfeng @fernandou 更加详细的,可以看看阮一峰老师的这篇 npm scripts 使用指南

@luoyjx 好的 顺便问一哈node --harmony-async-await 这种和谐模式在哪里有说明?我在node的doc里面没找到,只知道这种和谐模式可以使用async了。

L
luoyjx#510 年前

@hezhongfeng @fernandou 更加详细的,可以看看阮一峰老师的这篇 npm scripts 使用指南

L
luoyjx#210 年前

npm scripts有两种钩子:

  • pre 前置 prestart
  • post 后置 poststart

一般是执行某个命令的时候将npm install作为前置, 比如:

...
"scripts": {
	"prebuild": "npm install",
	"build": "webpack"
}

那么你在执行 npm run build的时候,npm会先去执行npm install,然后再执行build

当然,你也可以npm install之后干点别的, 比如:

"scripts": {
	"postinstall": "node bin/check_logs_dir.js"
}

这样就能在执行脚本之后做别的事。

L
liujavamail#110 年前

在package.json文件中,  再scripts中写你要执行的文件

"scripts": {
    "start": "node ./bin/http-server"
  }

参与回复

登录后即可参与回复。登录