[英]NPM Package Development - How can i execute the build command after package install?
how do i to generate the build folder after my package be installed? 安装软件包后如何生成生成文件夹?
i did this: 我这样做:
"scripts": {
"build": "babel ./src --out-dir ./build"
}
But when other user install the package the npm not build. 但是当其他用户安装软件包时,npm无法构建。
How can i execute the build command after install? 安装后如何执行build命令?
You should use "postinstall" in scripts. 您应该在脚本中使用“ postinstall”。
source: https://docs.npmjs.com/misc/scripts 来源: https : //docs.npmjs.com/misc/scripts
It's almost certainly best not to have a post-install step at all. 几乎可以肯定,最好根本没有安装后的步骤。 What you really want to do is to build the project before it is published , and then publish the built version to NPM (assuming that's what you are trying to do).
您真正想要做的是在发布项目之前先构建项目,然后将构建的版本发布到NPM(假设您正在尝试这样做)。 In that case, you might use a
prepublish
script: 在这种情况下,您可以使用
prepublish
脚本:
// package.json
"scripts": {
"build": "babel src -d build",
"prepublish": "npm run build"
}
And make sure the built files are included in your files array : 并确保构建的文件包含在文件数组中 :
// package.json
"files": ["build"]
Or that your source files are excluded in your .npmignore
: 或者,您的
.npmignore
中排除了您的源文件:
// .npmignore
/src/
If you really do need a post-install step for some reason, use a postinstall
script: 如果由于某些原因确实需要安装后步骤,请使用
postinstall
脚本:
// package.json
"scripts": {
"build": "babel src -d build",
"postinstall": "npm run build"
}
But I can't think of a use-case where this would be a good idea. 但是我想不出一个用例很好的主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.