简体   繁体   English

ng build之后的angular-cli run命令

[英]angular-cli run command after ng build

I am wondering how to extend ng build to run tasks after it has finished. 我想知道如何在完成后扩展ng build以运行任务。

At the moment, my end goal is to copy my 'package.json' to the dist folder. 目前,我的最终目标是将我的'package.json'复制到dist文件夹。

Something like this if I was using plain npm: 如果我使用普通的npm,这样的事情:

"postbuild": "cpx ./package.json ./dist/",

I know in the angular-cli.json I can use "assets" to copy static files, but it does not work for files outside of src. 我知道在angular-cli.json中我可以使用“assets”来复制静态文件,但它不适用于src之外的文件。 So, I'm wondering if I can do the copy task after ng build completes. 所以,我想知道在构建完成后我是否可以执行复制任务。

Define an npm script 定义npm脚本

"build":" "ng build"

and add the postbuild script, too. 并添加postbuild脚本。

"postbuild": "cpx ./package.json ./dist/",

This way the copy script gets called after you run npm run build . 这样,在运行npm run build之后会调用复制脚本。

You can execute any custom script before or after any npm script. 您可以在任何npm脚本之前或之后执行任何自定义脚本。 This is called 'hooks' and it is included in npm. 这被称为'钩子',它包含在npm中。 In your case you can execute a 'post' hook but keep in mind that it is also possible to execute 'pre' hook. 在你的情况下,你可以执行'post'钩子,但请记住,也可以执行'pre'钩子。

define these 3 scripts in your package.json: 在package.json中定义这3个脚本:

"hello": "echo execute hello",
"prehello": "echo execute prehello",
"posthello": "echo execute posthello"

You can find many more useful information about that here: https://www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html 您可以在此处找到更多有用的信息: https//www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM