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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With