« Back to home

Using only the generator of Angular-CLI

Posted on

In one of my previous posts, I wrote about Angular CLI. With this tool, you can simplify your work when dealing with Angular2 projects. This tool can create a template of a new Angular2 application where everything is set up and works perfectly. However, what if you want to have a build process of your application that is a bit different from what Angular CLI offers or you want to use this tool in an existing project which already has its own structure and build process? Can you still use some goodies from this CLI? Is this possible?

Yes it is. You can take as much as you want from this tool. All you need to do, is to install Angular-CLI with the command npm install -g angular-cli and then add a file angular-cli.json to the root folder of your project. Inside angular-cli.json, I put the content like this:

{
  "defaults": {
    "prefix": "",
    "sourceDir": "wwwroot",
    "styleExt": "css",
    "prefixInterfaces": false
  }
}

You can specify more options here for this CLI but this is enough for me. This file can be added to .gitignore as it does not have any influence on your project.

You also need this tool as a part of the development dependencies in package.json of your project. A command like this does the job: npm install angular-cli --save-dev.

After this you can use almost every command of CLI, for example:

ng g service
ng g route
ng g component

Some commands are impossible to use because we don’t have a full Angular-CLI project, for example:

ng serve
ng build

When use them, you get errors.

As you can see, you can have happiness and receive a helping hand from Angular CLI with development workflow and the building process of your choice.

Comments

comments powered by Disqus