Skip to content

Commit 515b579

Browse files
filipesilvaZhicheng Wang
authored and
Zhicheng Wang
committed
docs: add move in/out docs
Fix angular#3198
1 parent 2c537c4 commit 515b579

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Moving your project to Angular CLI
2+
3+
The easiest way to move an existing project to Angular CLI is to copy your
4+
application files into a new, empty CLI project.
5+
6+
Let's see how to do it step by step.
7+
Here we use a project made with the [official QuickStart](https://github.com/angular/quickstart)
8+
as an example, but you should be able to adjust these instructions to other setups.
9+
10+
Note for Windows users: we show unix commands here like `cp -r` to copy and `rm -rf` to delete files.
11+
Windows does not have these commands so use Explorer instead.
12+
13+
Start with preparing your existing project folder. We'll refer to it as `awesome-app`.
14+
- commit and push your existing changes.
15+
- clean your folder from temporary files and ignored files using `git clean -fdx`.
16+
- rename your project folder to `old-awesome-app`.
17+
18+
Now make a new project on the same parent folder as `old-awesome-app` using Angular CLI.
19+
- Verify you have the [Angular CLI prerequisites](https://github.com/angular/angular-cli#prerequisites).
20+
- Install the CLI globally: `npm install -g @angular/cli`.
21+
- Make a new app: `ng new awesome-app`.
22+
- Move into the folder: `cd awesome-app`.
23+
- Test your app works: `ng serve --open`.
24+
25+
Copy over your app files.
26+
- Remove the existing app: `rm -rf src/app src/styles.css src/index.html e2e`.
27+
- Copy `src/app/`, `src/index.html`, `src/styles.css` and `e2e/` from your old app.
28+
If you don't have a `src/` folder then these files and folders should be
29+
at the root of the old project instead.
30+
```
31+
cp -r ../old-awesome-app/src/app ./src/app
32+
cp ../old-awesome-app/src/index.html ./src/index.html
33+
cp ../old-awesome-app/src/styles.css ./src/styles.css
34+
cp -r ../old-awesome-app/e2e ./e2e/
35+
```
36+
- Don't copy `../old-awesome-app/src/main.ts`. Instead compare it to the new `./src/main.ts`
37+
and manually copy any extra code the old one has.
38+
- Compare `../old-awesome-app/package.json` to the new `./package.json` and add in your
39+
third party libraries and `@types/*` packages, project descriptions and any other fields.
40+
- Run `npm install` to install any packages you added.
41+
- Copy over any other files your app needs like images into `src/assets`.
42+
Adjust paths on your app to use this folder e.g. `<img src='assets/my-image.jpg>`.
43+
44+
There are a few adjustments you need to do to use the CLI build system.
45+
- Change any absolute paths you have for `templateUrl`, `styleUrls` or lazy loaded NgModules to
46+
relative paths instead.
47+
- Polyfills are listed in `./src/polyfills.ts` so remove `core-js` and `zone.js` from `index.html`.
48+
- SystemJS is not needed anymore, so remove it from `index.html` as well.
49+
- Instead of using `<script>` and `<link>` tags directly in `index.html`, use
50+
`angular-cli.json` instead.
51+
- Look for the `styles` array in `angular-cli.json` and add in any CSS files you have in
52+
`src/index.html`. Use a relative path from `./src/`.
53+
- Do the same for any remaining script tags as well, using the `scripts` array instead.
54+
55+
The final step is to copy your git history so you can continue working without losing anything:
56+
- Copy over the git folder: `cp -r ../old-awesome-app/.git .git`
57+
- Commit and push your changes as normal.
58+
59+
You can now delete `../old-awesome-app`, and you're done!
60+
61+
The CLI runs static analysis on your code to ensure it's AOT ready, so you might run into a few
62+
new compilation errors that weren't there before.
63+
Check out this [handy list of AOT Do's and Dont's](https://github.com/rangle/angular-2-aot-sandbox#aot-dos-and-donts)
64+
if you get any unfamiliar errors.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Moving your project out of Angular CLI
2+
3+
Each project is unique, and even though we try to cater to most setups in Angular CLI sometimes
4+
you need a custom setup.
5+
6+
Even if you need to use a different build system, you can still use other Angular CLI features
7+
like `ng generate`, `ng lint`, `ng test` and `ng e2e` by leaving in `angular-cli.json` and
8+
supporting files like `src/test.ts`.
9+
10+
Moving out of the CLI is very similar to [Moving into the CLI](moving-into-the-cli).
11+
You'll have to make a brand new project using your new project seed, move your app files and
12+
cater to any changes in the build process.
13+
14+
Start with preparing your existing project folder. We'll refer to it as `awesome-app`.
15+
- commit and push your existing changes.
16+
- clean your folder from temporary files and ignored files using `git clean -fdx`.
17+
- rename your project folder to `old-awesome-app`.
18+
19+
Now make a new project on the same parent folder as `old-awesome-app`.
20+
- Make a new app using your new project seed in a new `awesome-app` folder.
21+
- Move into the folder: `cd awesome-app`.
22+
23+
Copy over your app files.
24+
- Locate `app/`, `styles.css` and the end-to-end test folder in your new project.
25+
- Replace them with the corresponding files from `../old-awesome-app`.
26+
- If your styles are not in CSS, you'll need to convert them to CSS since the quickstart doesn't
27+
use style preprocessors. You can also add preprocessor support yourself.
28+
- Copy over the code your app needs from the `environments/` folder, if any.
29+
You'll have to find another way to switch environments on the Quickstart.
30+
- Don't copy `../old-awesome-app/src/main.ts`. It contains custom logic for the CLI
31+
`environments` feature. Instead compare code and take only what you need.
32+
- Do the same for `index.html`.
33+
- Compare `../old-awesome-app/package.json` to the new `./package.json` and add in your
34+
third party libraries and `@types/*` packages, project descriptions and any other fields.
35+
- Run `npm install` to install any packages you added.
36+
- Copy over any other files your app needs like images, icons, etc.
37+
38+
You might also need to make adjustments to conform to your new build system.
39+
- The CLI only allows relative paths in `templateUrl`, `styleUrls` or lazy loaded NgModules.
40+
You might need to change these.
41+
- Polyfills are listed in `../old-awesome-app/src/polyfills.ts`. Incorporate these into the new
42+
project.
43+
- The CLI lists used `<script>` and `<link>` tags in the `angular-cli.json` `scripts`
44+
and `styles` array. Check import these in your new project and add them accordingly.
45+
46+
The final step is to copy your git history so you can continue working without losing anything:
47+
- Copy over the git folder: `cp -r ../old-awesome-app/.git .git`
48+
- Commit and push your changes as normal.
49+
50+
You can now delete `../old-awesome-app`, and you're done!
51+
52+
Every project seed does things slightly different so if you are running into problems be sure
53+
to ask in their issue tracker.

0 commit comments

Comments
 (0)