/ng4all

Extensible, reliable, modular, PWA ready starter project for Angular (4 and beyond) with statically typed build and AoT compilation with Jquery and Bootstrap support

Primary LanguageJavaScriptMIT LicenseMIT

Introduction

Provides fast, reliable and extensible starter for the development of Angular projects.

angular-seed provides the following features:

  • Allows you to painlessly update the seed tasks of your already existing project.
  • Supports multiple Angular applications with shared codebase in a single instance of the seed.
  • Official Angular i18n support.
  • Ready to go, statically typed build system using gulp for working with TypeScript.
  • Production and development builds.
  • Ahead-of-Time compilation support.
  • Tree-Shaking production builds with Rollup.
  • Sample unit tests with Jasmine and Karma including code coverage via istanbul.
  • End-to-end tests with Protractor.
  • Development server with Livereload.
  • Following the best practices.
  • Manager of your type definitions using @types.
  • Has autoprefixer and css-lint support.
  • Provides full Docker support for both development and production environment
  • Support for Angular Mobile Toolkit

How to start

Note that this seed project requires node v4.x.x or higher and npm 2.14.7 but in order to be able to take advantage of the complete functionality we strongly recommend node >=v6.5.0 and npm >=3.10.3.

In order to start the seed use:

$ git clone --depth 1 https://github.com/itranga/ng4all.git
$ cd angular-seed

# install the project's dependencies
$ npm install
# fast install (via Yarn, https://yarnpkg.com)
$ yarn install  # or yarn

# watches your files and uses livereload by default
$ npm start

# generate api documentation
$ npm run compodoc
$ npm run serve.compodoc


# to start deving with livereload site and coverage as well as continuous testing
$ npm run start.deving

# dev build
$ npm run build.dev
# prod build, will output the production application in `dist/prod`
# the produced code can be deployed (rsynced) to a remote server
$ npm run build.prod

# dev build of multiple applications (by default the value of --app is "app")
$ npm start -- --app baz
$ npm start -- --app foo
$ npm start -- --app bar

Does not rely on any global dependencies.

How to start with AoT compilation

Note that AoT compilation requires node v6.5.0 or higher and npm 3.10.3 or higher.

In order to start the seed with AoT use:

# prod build with AoT compilation, will output the production application in `dist/prod`
# the produced code can be deployed (rsynced) to a remote server
$ npm run build.prod.aot

Tree-shaking with Rollup

This application provides full support for tree-shaking your production builds with Rollup, which can drastically reduce the size of your application. This is the highest level of optimization currently available.

To run this optimized production build, use:

# prod build with AoT compilation and Rollup tree-shaking, will output the production application in `dist/prod`
# the produced code can be deployed (rsynced) to a remote server
$ npm run build.prod.rollup.aot

Your project will be compiled ahead of time (AOT), and then the resulting bundle will be tree-shaken and minified. During the tree-shaking process Rollup statically analyses your code, and your dependencies, and includes the bare minimum in your bundle.

Notes

  • Beware of non-static/side-effectful imports. These cannot be properly optimized. For this reason, even though tree-shaking is taking place the developer still needs to be careful not to include non-static imports that are unnecessary, as those referenced imports will always end up in final bundle. Special attention should be given to RxJs, which makes heavy use of non-static/side-effectful imports: make sure you only add the operators you use, as any added operators will be included in your final production bundle.
  • UMD modules result in code that cannot be properly optimized. For best results, prefer ES6 modules whenever possible. This includes third-party dependencies: if one is published in both UMD and ES6 modules, go with the ES6 modules version.
  • During a production build, CommonJs modules will be automatically converted to ES6 modules. This means you can use them and/or require dependencies that use them without any issues.

Internationalization

Put i18n attribute to your html tag to mark it for translation, more information here: https://angular.io/docs/ts/latest/cookbook/i18n.html

Create a translation source file

# Your translation file will be generated here `dist/locale`
$ npm run i18n

Production build with your language

# Build prod app with the language file `dist/locale/messages.en.xlf`
$ npm run build.prod.rollup.aot -- --lang en

Dockerization

The application provides full Docker support. You can use it for both development as well as production builds and deployments.

How to build and start the dockerized version of the application

The Dockerization infrastructure is described in the docker-compose.yml (respectively docker-compose.production.yml. The application consists of two containers:

  • angular-seed - In development mode, this container serves the angular app. In production mode it builds the angular app, with the build artifacts being served by the Nginx container
  • angular-seed-nginx - This container is used only production mode. It serves the built angular app with Nginx.

Development build and deployment

Run the following:

$ docker-compose build
$ docker-compose up -d

Now open your browser at http://localhost:5555

Production build and deployment

Run the following:

$ docker-compose -f docker-compose.production.yml build
$ docker-compose -f docker-compose.production.yml up angular-seed   # Wait until this container has finished building, as the nginx container is dependent on the production build artifacts
$ docker-compose -f docker-compose.production.yml up -d angular-seed-nginx  # Start the nginx container in detached mode

Now open your browser at http://localhost:5555

Configuration

Default application server configuration

var PORT             = 5555;
var DOCS_PORT        = 4003;
var APP_BASE         = '/';

Configure at runtime

$ npm start -- --port 8080 --base /my-app/

Environment configuration

If you have different environments and you need to configure them to use different end points, settings, etc. you can use the files dev.ts or prod.ts in./tools/env/. The name of the file is environment you want to use.

The environment can be specified by using:

$ npm start -- --env-config ENV_NAME

Currently the ENV_NAMEs are dev, prod, staging, but you can simply add a different file "ENV_NAME.ts". file in order to alter extra such environments.

Change Log

You can follow the Angular change log here.

License

MIT