Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 543
mrshickadance Avatar asked Dec 12 '16 20:12

mrshickadance


People also ask

What happens after ng build?

ng build is the command you use when you're ready to build your application and deploy it. The CLI will analyze the application and build the files, all while optimizing the application as best as it can.

What do you get after running the NG new skills command?

Syntax. ng new command creates a workspace of given name with a default Angular Application. It provides interactive prompts to set optional configurations. All prompts have default values to choose.

What does ng build prod do?

ng build --env=prod / ng build --configuration=prod will change the project configuration to the configurations set in the environment. prod. ts file. It will not do any AOT, minification etc.


2 Answers

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.

like image 86
Alexander Ciesielski Avatar answered Sep 22 '22 12:09

Alexander Ciesielski


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

like image 20
pegaltier Avatar answered Sep 21 '22 12:09

pegaltier