JonnyBGod / angular2-webpack-advance-starter

An advanced Angular2 Webpack Starter project with support for ngrx/store, ngrx/effects, ng2-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
https://jonnybgod.github.io/angular2-webpack-advance-starter/
MIT License
48 stars 12 forks source link
advance angular angular2 angularclass angulartics2 electron javascript nativescript ngrx seed starter typescript webpack

Webpack and Angular 2

+

Angular 2 Webpack Advance Starter Integrations


Angular 2 Style Guide Build Status MIT license Dependency Status devDependency Status Gitter Chat

This is an advance starter project for Angular 2 apps based on AngularClass's angular2-webpack-starter and Nathan Walker's angular2-seed-advanced.

I would like to thank both for their great work and collaboration. Please refer to both projects' pages for extra documentation.

Integration with:

Multiple Platforms
The zen of multiple platforms. Chrome, Android and iPhone all running the same code.
Desktop
Programming Nirvana. Mac and Windows desktop both running the same code.

Table of Contents

Enhanced development workflow

Enhanced testing support options

Advice: If your project is intended to target a single platform (i.e, web only), then angular2-webpack-starter is likely more than suitable for your needs. However if your project goals are to target multiple platforms (web, native mobile and native desktop), with powerful out of the box library support and highly configurable/flexible testing options, then you might want to keep reading.

Additionally, this seed is intended to push a couple boundaries so if you see dependencies that are bleeding edge, this is intentional.

Getting Started

Dependencies

npm install -g nativescript

Usage

git clone --depth 1 https://github.com/JonnyBGod/angular2-webpack-advance-starter.git
cd angular2-seed-advanced

# install the project's dependencies
npm install or yarn install

# start the server
npm start

# use Hot Module Replacement
npm run start:hmr

Other commands

build files

# development
npm run build:dev
# production (jit)
npm run build:prod
# AoT
npm run build:aot

hot module replacement

npm run server:dev:hmr

watch and build files

npm run watch

run unit tests

npm run test

watch and run our tests

npm run watch:test

run end-to-end tests

# this will start a test server and launch Protractor
npm run e2e

continuous integration (run unit tests and e2e tests together)

# this will test both your JIT and AoT builds
npm run ci

run webdriver (for end-to-end)

npm run webdriver:update
npm run webdriver:start

run Protractor's elementExplorer (for end-to-end)

npm run webdriver:start
# in another terminal
npm run e2e:live

generate docs

npm run docs

build Docker

npm run build:docker

Electron App

Develop

Mac:      npm run start:desktop
Windows:  npm run start:desktop:windows

Build: Electron App for Mac, Windows or Linux for distribution

Mac:      npm run build:desktop:mac
Windows:  npm run build:desktop:windows
Linux:    npm run build:desktop:linux

All:      npm run build:desktop

Framework How-Tos

i18n

Change Detection OnPush Note

Please Note: The seed uses Angular's ChangeDetectionStrategy.OnPush by default which requires some understanding of immutability and one-way data flows. Please check out the following resources to learn more:

If you experience issues with changes not occuring in your views, you can disable this by commenting out these lines. The seed uses OnPush by default because it provides optimal performance and if you decide to turn it off while developing your application, you can always turn it back on when you're ready to refactor your data services to utilize OnPush properly.

General Best Practice Guide to Sharing Code

There’s actually only a few things to keep in mind when sharing code between web/mobile. The seed does take care of quite a few of those things but here’s a brief list:

If you were thinking about doing: alert('Something happened!');, Don't. Instead inject WindowService:

constructor(private win: WindowService) {}

public userAction() {
  if (success) {
    // do stuff
  } else {
    this.win.alert('Something happened!');
  }
}

This ensures that when the same code is run in the {N} app, the native dialogs module will be used.

The advice Nathan Walker's likes to give, and I fully support it, is:

Code with web mentality first. Then provide the native capability using Angular’s {provide: SomeWebService, useClass: SomeNativeService } during bootstrap.

There are some cases where you may want to use useValue vs. useClass, and other times may need to use useFactory. Read the Angular docs here to learn more about which you may need for your use case.

How best to use for your project

Setup

NOTE: This should be done first before you start making any changes and building out your project. Not doing so will likely result in dificulty when trying to merge in upstream changes later.

  1. Download a zip of the seed. (Do not fork)
  2. npm run git.setup - This will initialize git as well as setup upstream properly.
  3. git remote add origin ...your private repo...
  4. npm run git.prepare - This will prepare git to handle the merge
  5. npm run git.merge - This will fetch upstream and run the first merge (*Important)
    • IMPORTANT: You will see a wall of Conflicts after doing above (a Conflict for every single file). This is normal. There actually will not be any problematic conflicts as it's just reporting every single file which both sides (upstream and your first commit) added.
  6. git add .; git commit -m'ready'. Yes, you will be committing all those conflicts, which actually are not a problem in this 1 time case.
  7. Now you have git setup and ready to develop your application as well as merge in upstream changes in the future.
  8. npm install (and all other usage docs in this README apply)
  9. Create a new framework for your application in src/app/frameworks to build your codebase out. Say your app is called AwesomeApp, then create awesomeapp and start building out all your components and services in there. Create other frameworks as you see fit to organize.
  10. If you don't want an integration that comes out of box with this seed; for example. let's say you don't want to use i18n. Then just delete the i18n, remove ng2-translate as dependency root package.json and nativescript/package.json. Then remove any references to i18n throughout.

Merging latest upstream changes

  1. npm run git:merge:preview - This will fetch upstream and show you how the merge would look
  2. npm run git:merge - This will actually do the merge
  3. Handle any conflicts to get latest upstream into your application.
  4. Continue building your app.

You can read more about syncing a fork here.

If you have any suggestions to this workflow, please post here.

Configuration

Configuration files live in config/ we are currently using webpack, karma, and protractor for different stages of your application.

Use config/custom/ configuration files when possible to add your custom configurations or override our configurations. This will help you when updating upstream.

AoT Don'ts

The following are some things that will make AoT compile fail.

More Documentation

angular2-webpack-starter

angular2-seed-advanced

Contributing

Please see the CONTRIBUTING and CODE_OF_CONDUCT files for guidelines.


License

MIT