Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upProposal: pre/post-commands for Angular CLI #16308
Comments
This comment has been minimized.
This comment has been minimized.
This overlaps with this feature request #11787 Maybe you can add the details there? |
This comment has been minimized.
This comment has been minimized.
Thanks @lacolaco |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command (mark with an
x
)Description
This idea is inspired by npm-scripts. I'd like to introduce a feature that allows us to define a
prebuild
script inangular.json
.That is useful and powerful for solving build process issues like this:
#4318
Currently, Angular CLI doesn't have hooks on its commands. To execute preprocessing scripts like code-generation before
ng build
, developers have to do it manually.In general,
ng build
is often aliased asnpm run build
. And for production build, oftenng build --prod
is aliased as a different command likenpm run build:prod
. Then mypackage.json
becomes like below;In that case, for adding preprocess script, I have to add it into each scripts like this;
I can use
pre-
hook of npm-scripts, however, a problem is there are two build scripts. It brings a lot of scripts inpackage.json
.This problem can be more serious in a workspace having multiple projects. Each build commands have to take project identifier and often these are separated as different npm-scripts.
Too many npm-scripts are hard to maintain. So I'd like to propose Angular CLI's command hook feature.
Describe the solution you'd like
CLI command hook is a mechanism to execute a script before/after running CLI's command. It is not only for
ng build
but all command.With the hook, pre-build code-generation is able to be configured in
angular.json
like below;Once configuring this, it can work with
--prod
or any--configuration
s because each configuration can have its ownhooks
option to override.And any architect commands can be configured as well as
build
. Each architect author doesn't have to know about that.Each hook script will be executed at the location of
angular.json
. The initialCWD
is the workspace root.