Skip to content

🎉 An example Address Book project built with Angular 4, Typescript and Webpack with AOT(Ahead of Time) compilation. It also uses Pubnub for sending and receivig notifications when a new tag is added.

License

Notifications You must be signed in to change notification settings

mecp/ngx-addressbook

Repository files navigation

Introduction

An example Address Book project built with Angular 4, Typescript and Webpack. It also uses Pubnub for sending and receivig notifications when a new tag is added.

To be able to use Pubnub you will need to put your own publish and subscribe key obtained from Pubnub Dashboard, otherwise it will push the notification locally. Once you have obtained the keys please put them inside notification.service.ts.

  // Put your publish and subscribe key here
  private publishKey = '';
  private subscribeKey = '';

Demo


App is deployed here for demo ⇢ ngx-addressbook

Quick start

Make sure you have Node version >= 6.0 and NPM >= 3

Clone/Download the repo then edit app.component.ts inside /src/app/app.component.ts

# clone our repo
# --depth 1 removes all but one .git commit history
git clone --depth 1 https://github.com/mecp/ngx-addressbook.git

# change directory to our repo
cd ngx-addressbook

# install the repo with npm
npm install

# start the server
npm start

# use Hot Module Replacement
npm run server:dev:hmr

# if you're in China use cnpm
# https://github.com/cnpm/cnpm

go to http://0.0.0.0:3000 or http://localhost:3000 in your browser

Table of Contents

File Structure

We use the component approach in our starter. This is the new standard for developing Angular apps and a great way to ensure maintainable code by encapsulation of our behavior logic. A component is basically a self contained app usually in a single file or a folder with each concern as a file: style, template, specs, e2e, and component class. Here's how it looks:

angular2-webpack-starter/
 ├──config/                        * our configuration
 |   ├──helpers.js                 * helper functions for our configuration files
 |   ├──spec-bundle.js             * ignore this magic that sets up our Angular testing environment
 |   ├──karma.conf.js              * karma config for our unit tests
 |   ├──protractor.conf.js         * protractor config for our end-to-end tests
 │   ├──webpack.dev.js             * our development webpack config
 │   ├──webpack.prod.js            * our production webpack config
 │   └──webpack.test.js            * our testing webpack config
 │
 ├──src/                           * our source files that will be compiled to javascript
 |   ├──main.browser.ts            * our entry file for our browser environment
 │   │
 |   ├──index.html                 * Index.html: where we generate our index page
 │   │
 |   ├──polyfills.ts               * our polyfills file
 │   │
 │   ├──app/                       * WebApp: folder
 │   │   └──app.component.ts       * a simple version of our App component components
 │   │
 │   └──assets/                    * static assets are served here
 │       
 ├──tslint.json                    * typescript lint config
 ├──typedoc.json                   * typescript documentation generator
 ├──tsconfig.json                  * typescript config used outside webpack
 ├──tsconfig.webpack.json          * config that webpack uses for typescript
 ├──package.json                   * what npm uses to manage it's dependencies
 └──webpack.config.js              * webpack main configuration file

Getting Started

Dependencies

What you need to run this app:

  • node and npm (brew install node)
  • Ensure you're running the latest versions Node v6.x.x+ (or v7.x.x) and NPM 3.x.x+

If you have nvm installed, which is highly recommended (brew install nvm) you can do a nvm install --lts && nvm use in $ to run with the latest Node LTS. You can also have this zsh done for you automatically

Once you have those, you should install these globals with npm install --global:

  • webpack (npm install --global webpack)
  • webpack-dev-server (npm install --global webpack-dev-server)
  • karma (npm install --global karma-cli)
  • protractor (npm install --global protractor)
  • typescript (npm install --global typescript)

Installing

  • fork this repo
  • clone your fork
  • npm install webpack-dev-server rimraf webpack -g to install required global dependencies
  • npm install to install all dependencies or yarn
  • npm run server to start the dev server in another tab

Running the app

After you have installed all dependencies you can now run the app. Run npm run server to start a local server using webpack-dev-server which will watch, build (in-memory), and reload for you. The port will be displayed to you as http://0.0.0.0:3000 (or if you prefer IPv6, if you're using express server, then it's http://[::1]:3000/).

server

# development
npm run server
# production
npm run build:prod
npm run server:prod

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

build Docker

npm run build:docker

Configuration

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

AoT Don'ts

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

  • Don’t use require statements for your templates or styles, use styleUrls and templateUrls, the angular2-template-loader plugin will change it to require at build time.
  • Don’t use default exports.
  • Don’t use form.controls.controlName, use form.get(‘controlName’)
  • Don’t use control.errors?.someError, use control.hasError(‘someError’)
  • Don’t use functions in your providers, routes or declarations, export a function and then reference that function name
  • @Inputs, @Outputs, View or Content Child(ren), Hostbindings, and any field you use from the template or annotate for Angular should be public

Questions or Feedback

Deployment

Netlify

You can quickly create a free site to get started using this starter kit in production on Netlify:

Deploy to Netlify

Project is built on Angular Starter


An Angular 4 starter kit featuring Angular 4 and Angular 4 (Ahead of Time Compile, Router, Forms, Http, Services, Tests, E2E), Karma, Protractor, Jasmine, Istanbul, TypeScript, @types, TsLint, Codelyzer, Hot Module Replacement, and Webpack 2 by AngularClass.

If you're looking to learn about Webpack and ES6 Build Tools check out ES6-build-tools If you're looking to learn TypeScript see TypeStrong/learn-typescript


License

MIT

About

🎉 An example Address Book project built with Angular 4, Typescript and Webpack with AOT(Ahead of Time) compilation. It also uses Pubnub for sending and receivig notifications when a new tag is added.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published