简体   繁体   中英

angular-cli run command after ng build

I am wondering how to extend ng build to run tasks after it has finished.

At the moment, my end goal is to copy my 'package.json' to the dist folder.

Something like this if I was using plain 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. So, I'm wondering if I can do the copy task after ng build completes.

Define an npm script

"build":" "ng build"

and add the postbuild script, too.

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

This way the copy script gets called after you run npm run build .

You can execute any custom script before or after any npm script. This is called 'hooks' and it is included in npm. In your case you can execute a 'post' hook but keep in mind that it is also possible to execute 'pre' hook.

define these 3 scripts in your package.json:

"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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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