1

I have developed an Angular application using tools such as NPM (I did not use the Angular CLI). What is the best way to migrate the project to the CLI project model? For example, I want to be able to use commands like ng serve.

7
  • You mean to say you developed Angular Application without Angular CLI !!! Commented Aug 19, 2019 at 12:28
  • Can you please explain in detail what do you mean developed using npm and what do you want to do in Angular CLI. Commented Aug 19, 2019 at 12:28
  • @AdritaSharma i developed angular application without Angular CLI. now i am using "npm start" to run application. i want to convert it to Angular CLI so that i can use "ng serve" Commented Aug 19, 2019 at 12:31
  • I think you are using angular.js. right? angular cli is for angular 2+ Commented Aug 19, 2019 at 12:36
  • 1
    @LibinCJacob No not angular.js. It is Angular 2+ only but I developed without CLI. now i want to convert project into CLI Commented Aug 19, 2019 at 12:42

1 Answer 1

4

To convert an Angular project to use the Angular CLI, you could follow these steps.

1. Install the CLI

npm install -g @angular/cli

2. Create a new CLI Project

ng new my-first-project
cd my-first-project
ng serve

3. Copy your existing code files into the new CLI Project

4. Configure your Angular Workspace

Differences between Angular CLI and Other Build Systems

Notes from Migrating a project to Angular CLI build system

  • Angular CLI may use multiple tsconfig.json files (be sure to setup dependencies between files correctly)
  • ng serve and ng test compile your typescript into memory rather than physical files.
  • If ng test doesn't work and gives cryptic errors look into the pollyfills.ts file and start uncommenting lines.
  • Consider locking package.json versions with exact version numbers, shrinkwrap, lockfile, or yarn. There is no joy in debugging @types, tsc versions and incompatible modules.
  • Building with ng build --prod (which uses AOT compilation) is a lot more strict than the default typescript rules with ng serve.
  • Using sass for css:
    1. When creating new project: ng new my-first-app --style=scss
    2. Or modify angular.json:
"schematics": {
      "@schematics/angular:component": {
      "styleext": "scss"
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.