Angular-cli: How to hook 3rd party scripts before serving / building an app with angular-cli?

Created on 30 Mar 2017  路  3Comments  路  Source: angular/angular-cli


Question:
I have a script that generates typescript classes from a source descriptor. Those classes are used by the angular project.
However, I have to manually run the script when the descriptor changes.
Is it possible to hook some event in angular cli, so the script can be called before an ng build or ng serve, for example?
Ideally the descriptor should be watched during the ng serve, and the callback invoked whenever it changes, such as what happens with SASS -> CSS.

Versions.

@angular/cli: 1.0.0
node: 7.7.3
os: linux x64

Most helpful comment

Thanks @coryrylan, this is a nice workaround.
I've been researching on this and found the issue https://github.com/angular/angular-cli/issues/1656 which, if done, could allow writing a webpack plugin for watching resources on runtime and emitting additional files.
But, as it seems, direct access to the webpack configuration won't be allowed (unless the project is ng ejected, which is not ideal either, because we loose some benefits of angular-cli).
Maybe in the future it will be possible to write angular-cli plugins, let's see.

All 3 comments

I have a project that does something similar. You can use npm scripts in your package.json

"start": "pretasks && ng serve"

Then run npm run start

This will run the prebuild task before running the project. As for runtime build hooks I am unsure.

Thanks @coryrylan, this is a nice workaround.
I've been researching on this and found the issue https://github.com/angular/angular-cli/issues/1656 which, if done, could allow writing a webpack plugin for watching resources on runtime and emitting additional files.
But, as it seems, direct access to the webpack configuration won't be allowed (unless the project is ng ejected, which is not ideal either, because we loose some benefits of angular-cli).
Maybe in the future it will be possible to write angular-cli plugins, let's see.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericel picture ericel  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments