Angular2 supports Typescript, Of course Typescript has advantages for better coding. Here I am not going discuss advantages of Typescript.  Lets create basic Angular2 project for both development and production.
Webpack - Click here to read webpack setup for Angular2

Project structure 

Observe below diagram. 
  • app folder - this contains Typescript files for app functionality. Here main.ts is the starting probe of our app
  • css folder - contains styles required for app
  • dist folder - contains production version of the project (generated from development files)
  • production folder - contains production suitable HTML and TS files 
  • index.html - HTML file used in development mode
  • package.json - contains meta data and dependencies
  • systemjs.config.js - SystemJS configuration file
  • tsconfig.json - Typescript configuration file
  • typings.json - Typings dependencies

Download the project

I have uploaded this project to github. You can download it from here

by using git :

git clone https://github.com/SodhanaLibrary/angular2-prod-dev-setup.git

Install dependencies :

npm install
This will install all dependencies including typings

Run this project :

npm start
Above command will transpile Typescript files to JS files and run the lite-server. Now you can see the localhost with angular2.

Generate production version :

npm run build_prod
Above command will create dist folder with all its dependencies and css files.  Now just open index.html of dist folder in browser, You can your angular app running

Index.html - development VS production

index.html code of development and production is different. Observe below code.

Development index.html

Here we need to have systemjs configuration file. SystemJS will load our main angular application based on the configuration
<html>
  <head>
    <title>Angular QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>
  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>

Production index.html

Here you don't need to import system js configuration file, you will directly import bundle.min.js file. This bundle js file contains all javascript code including libraries. It will be generated by browserify while generating production version. 
<html>
  <head>
    <title>Angular QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/styles.css">
    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="dependencies/shim.min.js"></script>
    <script src="dependencies/zone.js"></script>
    <script src="dependencies/Reflect.js"></script>
    <script src="dependencies/system.src.js"></script>

  </head>
  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
    <script src="bundle.min.js"></script>
  </body>
</html>

Main.ts - development vs production

Maint.ts is the app starting point. development version is in app folder, production version is in production folder.

development main.ts

AppModule is the starting point of the app
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

Production main.ts

Here enableProdMode is called. Which will turn off assertions and checks, and improves performance. 
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from '../app/app.module';
import {enableProdMode} from '@angular/core';

enableProdMode();
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

Package.json

Finally package.json which will have all commands, metadata and dependencies. Find below for commands
    {
    "clean": "rm -rf dist && mkdir dist && mkdir dist/dependencies",
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "build": "npm run clean && tsc",
    "minify": "uglifyjs dist/bundle.js --screw-ie8 --compress --mangle --output dist/bundle.min.js",
    "build_prod": "npm run build && browserify -s main production/main.prod.js > dist/bundle.js && npm run minify && cp -R css dist/css && cp production/index.html dist/ && npm run build_prod_depds",
    "build_prod_depds": "cp node_modules/core-js/client/shim.min.js dist/dependencies/ && cp node_modules/zone.js/dist/zone.js dist/dependencies/ && cp node_modules/reflect-metadata/Reflect.js dist/dependencies/ && cp node_modules/systemjs/dist/system.src.js dist/dependencies/ && cp systemjs.config.js dist/"
    }

37 comments:

  1. Thank you for your post.
    I modified the package.json in order to make it working on windows

    {
    "name": "angular-quickstart",
    "version": "1.0.0",
    "scripts": {
    "clean": "rd /s /q dist && mkdir dist && mkdir dist\\dependencies",
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "build": "npm run clean && tsc",
    "minify": "uglifyjs dist/bundle.js --screw-ie8 --compress --mangle --output dist/bundle.min.js",
    "build_prod": "npm run build && browserify -s main production\\main.prod.js > dist\\bundle.js && npm run minify && xcopy /I css dist\\css && copy production\\index.html dist\\ && npm run build_prod_depds",
    "build_prod_depds": "copy node_modules\\core-js\\client\\shim.min.js dist\\dependencies\\ && copy node_modules\\zone.js\\dist\\zone.js dist\\dependencies\\ && copy node_modules\\reflect-metadata\\Reflect.js dist\\dependencies\\ && copy node_modules\\systemjs\\dist\\system.src.js dist\\dependencies\\ && copy systemjs.config.js dist\\"
    },
    ...

    ReplyDelete
  2. thank you, but now, how i can to up my app to host?

    ReplyDelete
    Replies
    1. run "npm run build_prod" which creates dist folder with production ready files, you can host these files on your web server

      Delete
  3. where have you used webpack?

    ReplyDelete
  4. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from TypeScript Training in Chennai

    ReplyDelete
  5. I Appreciate Your Efforts In Preparing This Post. I Really Like Your Blog Articles.
    [url=http://procinehub.com/]best baby photographer in jalandhar[/url]
    [url=http://procinehub.com/]best fashion photographer in Chandigarh[/url]
    [url=https://www.styleandgeek.com/home-remedies-hair-fall//]home remedies for hair fall[/url]
    [url=https://www.styleandgeek.com/top-25-home-remedies-to-remove-tanning//home-remedies-hair-fall//]home remedies to get rid of tanning[/url]
    [url=https://www.lms.coim.in//]Online Digital Marketing Training[/url]

    ReplyDelete

  6. This is really an amazing and thank you so much for sharing


    คาสิโนออนไลน์ที่น่าเชื่อถือและมีความเป็นมืออาชีพที่สุดในตอนนี้
    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร สล็อตออนไลน์ กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> Goldenslot
    สนใจร่วมสนุกกับ คาสิโนออนไลน์ คลิ๊กได้เลย
    มีทั้งคาสิโนออนไลน์ หวยออนไลน์ ฟุตบอลออนไลน์ สล็อตออนไลน์ และอื่นๆอีกมากมาย

    ReplyDelete
  7. Thanks for posting
    my webside techwolk.in/Sonsindiasong
    I have Webside techwolk.in/Sonsindiasong for Related by All type Songs.

    ReplyDelete
  8. Thanks for posting
    my website techwolk is related to technology


    ReplyDelete

  9. Great post You are sharing much information keep it up ..awesome post


    I am sharingbiography ofBest Country In The World For LivingCheck my link for more information.


    ReplyDelete

  10. Great post You are sharing much information keep it up ..awesome post


    I am sharingbiography ofWHAT IS MUTUAL FUND? HOW TO INVEST AND ITS TYPES Check mlink for more information.

    ReplyDelete
  11. Great post You are sharing much information keep it up ..awesome post


    I am sharingbiography ofHow to Start an Event Management Company? Check mlink for more information.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Great post You are sharing much information keep it up ..awesome post



    I am sharing of top-10-richest-actor-in-india Check my link for more information.

    ReplyDelete
  14. Great post You are sharing much information keep it up ..awesome post



    I am sharing <biographyof TOP 10 HIGHEST PAYING JOB IN INDIA
    Check my link for more information.

    ReplyDelete
  15. Great post You are sharing much information keep it up ..awesome post


    I am sharing <biography
    of top-10-young-entrepreneur-in-india Check mlink for more information.

    ReplyDelete
  16. Great post You are sharing much information keep it up ..awesome post


    I am sharing <<a href="/”> biography</a> on top-10-richest-person-in-world.Check my link for more information.


    ReplyDelete
  17. Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.PHP Training in Chennai

    PHP Online Training in Chennai

    Machine Learning Training in Chennai

    iOT Training in Chennai

    Blockchain Training in Chennai

    Open Stack Training in Chennai

    ReplyDelete
  18. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspried me to read more. keep it up.

    AWS training in Chennai

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training

    ReplyDelete
  19. You can say that Java Swing is a zombie: It is still available and in use in its latest development state, but makes no progress in regard of improvements. ... Desktop GUIs are even more dead than Java Swing, because “mobile first” and “web second” don't leave much room for “desktop third”.
    Java Training in Chennai

    Java Training in Bangalore

    Java Training in Hyderabad

    Java Training in Coimbatore

    Java Training

    ReplyDelete
  20. It is certainly safe to update. With many people coming to the forum to get help with problems, it likely appears there are far more issues than exist. I haven't experienced any issues with Android 10. Most of the ones reported in the forum were easily fixed with Factory Data Reset.keep up!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  21. thanks for sharing the info we look forward for more it is so good
    AWS Training in Hyderabad

    ReplyDelete
  22. Angular2 supports Typescript, Of direction Typescript has benefits for higher coding. Here I am now not going discuss benefits of Typescript. Lets create fundamental Angular2 undertakings for each development and manufacturing. Usually the employer pays the agency a fee equivalent to a percentage of the new employee's starting salary. In the case of temporary workers, the employer often pays the employee's wages to the recruitment agency, which then passes on an agreed rate to the employee, keeping a percentage for themselves. Otherwise known as employment agencies, recruitment agencies companies act as the go-between for employers and jobseekers. They work on behalf of employers to find suitable candidates to fill their vacancies. Many employers use them, and signing up will sometimes give you access to jobs that aren't advertised elsewhere.

    ReplyDelete
  23. Above command will create dist folder with all its dependencies and css files. Now simply open index.Html of dist folder in browser, You can your angular app walking Knowing what's a BPO provider and peo services and what are the necessities of business processing outsourcing will truly help you advantage perception while thinking about hiring a BPO in your commercial enterprise. The variety of aid and talents supplied are an clean manner to streamline your work procedures at a less expensive fee! Although the paintings setup and expectancies related to outsourcing may be pretty exceptional from the standard enterprise partnerships that you are used to, stringent protocols and sophisticated tracking technology are without problems tackled with open and regular communication.

    ReplyDelete
  24. Here I am no longer going talk blessings of Typescript. Lets create fundamental Angular2 venture for both improvement and production. Index.Html code of development and production is exclusive. Observe beneath code. Data labels are text elements that describe individual data points. Displaying data labels. You may display data labels for all data points in the chart, for all data points in a particular series, or for individual data points. For information, see Displaying Data Labels. AI Platform data annotation services Labeling Service enables you to request human labeling for a collection of data that you plan to use to train a custom machine learning model. Prices for the service are computed based on: The number of human labelers for each data item.

    ReplyDelete
  25. Here I am no longer going talk blessings of Typescript. Lets create fundamental Angular2 venture for both improvement and production. Index.Html code of development and production is exclusive. Observe beneath code. Data labels are text elements that describe individual data points. Displaying data labels. You may display data labels for all data points in the chart, for all data points in a particular series, or for individual data points. For information, see Displaying Data Labels. AI Platform https://thestartupmag.com/4-main-benefits-data-labeling-can-bring-company/ data annotation services Labeling Service enables you to request human labeling for a collection of data that you plan to use to train a custom machine learning model. Prices for the service are computed based on: The number of human labelers for each data item.

    ReplyDelete
  26. "Above command will create dist folder with all its dependencies and css files. Now simply open index.Html of dist folder in browser, You can your angular app walking Knowing what's a BPO provider and peo services and what are the necessities of business processing outsourcing will truly help you advantage perception while thinking about hiring a BPO in your commercial enterprise. The variety of aid and talents supplied are an clean manner to streamline your work procedures at a less expensive fee! Although the paintings setup and expectancies related to outsourcing may be pretty exceptional from the standard enterprise partnerships that you are used to, stringent protocols and sophisticated tracking technology are without problems tackled with open and regular communication.
    "

    ReplyDelete

Blogroll

Popular Posts