Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 required libraries

I would like to start working with the Angular2 Beta, but I am facing a few problems regarding the required libraries.
I am using Eclipse and it's TypeScript Plugin.
Also, I am using SystemJSas module loader.
My problem is that if I install Angular2 using npm install angular2 it loads the whole Angular-Project, including the CommonJS-Version, ES6-Version and the TypeScript-Version. This results in a over 30 MB big folder with almost 2000 files, though I only need the TypeScript-Version (still a few 100 files), without examples.
Also, importing the /ts-folder in Eclipse gives me errors, that the modules from "rxjs" do not exist ("rxjs/Subject"...). So i guess i have to download that project too.
Using the package.json used in the 5 Min Quickstart, npm install downloads over 80MB (almost 10000 files), and I am sure, I don't need all those files.
So i would like to know, which files are really needed by Angular2 and how can i download them?
Should i create my own package.json-File? Or is there a even simpler way?

EDIT: Taking a look at our (working) Angular 1.X Project, i can see a single angular.js file, as well as files for the different modules (like restangular.js, angular-route.js etc.), in total about 10 files.
What i am now looking for is an angular2 counterpart of those files.
Do those counterparts exist? Where can i find them?

like image 200
Robert P Avatar asked Jan 07 '16 09:01

Robert P


Video Answer


1 Answers

"What i am now looking for is an angular2 counterpart of those files":

<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

You need those 4 .js (not .ts) files.

"Where can i find them?" They got downloaded with npm. You can keep those 4 and delete everything else. You can also get them from a CDN, or download them manually.

<!-- 1. Load libraries -->
<script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>

HOWEVER. These are already compiled javascript files, and they'll work for you if you write your app using JS, but right now 90% of the scarse documentation you will find about Angular 2 is on typescript and in order to work with typescript you'll need the source files of Angular 2 which is the whole package you are getting.

My suggestion if you are doing it in typescript: Don't worry about all those files getting downloaded, they are meant for development, not neccesarily part of your build. You can only include the ones I told you in your build and that will keep you real app small. Also you are not suppose to add all those files into the git repo or w/e repo you are using, the idea is that you have git ignore the whole "node_modules" folder and you only commit the package.json file, which will work for other developers so they run npm install and they get all the dependencies themselves. So all those files are only meant to be in dev machines, you don't have to worry about them making you app too big cause they won't be part of your app.

like image 123
Langley Avatar answered Sep 19 '22 12:09

Langley