Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use NPM to create a production build of an Angular2 project

Tags:

npm

angular

I created a project using the Angular2 quickstart https://angular.io/docs/js/latest/quickstart.html

I changed it completely to do my things, some usage of webcams, indexedDB and things like that :-).

The thing right now is that I've been using npm as the site recommends and it feels wrong now just changing to Gulp to create a build, instead of creating a build script on npm.

The next issue is that I've never done such a thing and I'm completely lost... do you know of any build script I could use/adapt? Or should I switch to Gulp?

Thank you

like image 764
RollWhisTler Avatar asked Jun 12 '16 10:06

RollWhisTler


People also ask

What is difference between ng build and NPM build?

ng-cli provides a easier way to build angular2 based apps. Npm provides modules for your application (like bootstrap, primeng etc.) Angular-cli is really just a swiss army knife for angular developers.

What is use of NG build -- prod?

ng build command compiles the Angular app into an output directory named dist/ at the given output path. This command must be executed from within the working directory. The application builder in Angular uses the webpack build tool, with configuration options specified in the workspace configuration file (angular.


1 Answers

I see, now I think I understand where the misunderstanding is. The link you provided is for Angular2 using Javascript. The best way to create a production Angular2 build is to use Typescript (and I believe it's the only officially supported way at this point as well). Here is a link to the tutorial using Typescript. If you don't know what that is, here's a SO question on it.

Once you learn how to use Angular2 with Typescript, I recommend reading this article on Angular2 in production.

Also, they are currently working on a command-line interface that will automatically build your app for production. They've released it but it's buggy at this point.

like image 50
Gab Avatar answered Nov 15 '22 06:11

Gab