Angular-cli different versions on one computer

I work with Angular2 in several projects. Each of these projects uses its own version angular-cli, so I need to be able to run and compile for production each separately with the correct version angular-cli. When I installed angular-clilocally using save-devng commands were not found, so I cannot create an assembly distribution for the project.

So the question is, how can I have multiple versions angular-clion the same computer without a global installation (with the -g option)? Is it possible to run ng commands without a global installation angular-cli?

+14
source share
5 answers

NVM, Node Version Manager Node.

Node 6.9.5 Angular2 , Node 10 Angular6 - .

, , , .

+2

ANGULAR CLI, :

node_modules/.bin/ng <ANY NG COMMAND>

ng <ANY NG COMMAND>

, , package.json ( node_modules)

npm node_modules/.bin ( ):

'npm bin'/ng <ANY NG COMMAND>

, npm bin .

ng scripts package.json, :

npm run ng -- <NG_OPTIONS>

-- , ng.

ng, , @angular/cli, npx:

npx @angular/cli@7 new <APP_NAME>

npx @angular/cli @7 ng .

- ( @angular/cli ng new). ng serve @6- CLI @7 :

cd <APP_NAME>
npx @angular/cli@6 serve
+20

, - , , , . @angular/cli@1.7.3 , , ( 5.0), @angular/cli@6.0.0. npx, , npx

npx frpm npm

npm install -g npx

Cli-. @angular/cli@latest @angular/cli .

npx -p @angular/cli@6.0.0 ng new my-project

ng -v, . npx , ng, .

npx ng -v //or npx ng -version

npx ng generate component my-component

npx ng ./node_modules/.bin/ .

+9

:

  1. npm init.
  2. Angular-CLI, .
  3. package.json.
  4. / Angular, CLI.

0

Dockerfile

FROM node:8
WORKDIR /app
RUN npm install -g @angular/cli@6.1.1

docker build . -t angular/ng6.1.1

docker run --rm -it -v $(pwd):/app angular/ng6.1.1 ng new hello-angular

You will find the hello-angular project created in your local folder, and if you want to use a different angular version, change the angular / cli version in the Docker file and create a new docker image to create a new angular project.

0
source

Source: https://habr.com/ru/post/1016035/


All Articles