Giter Club home page Giter Club logo

angular2-rocks's Introduction

Angular2 Rocks Starter Kit

Build Status Dependency Status devDependency Status Issue Stats Issue Stats MIT license

This seed repo serves as an Angular 2 starter for anyone looking to get up and running with Angular 2 and TypeScript fast. Using a Webpack for building our files and assisting with boilerplate. We're also using Protractor for our end-to-end story and Karma for our unit tests.

  • Best practices in file and application organization for Angular 2.
  • Ready to go build system using Webpack for working with TypeScript.
  • Angular 2 examples that are ready to go when experimenting with Angular 2.
  • A great Angular 2 seed repo for anyone who wants to start their project.
  • Testing Angular 2 code with Jasmine and Karma.
  • Coverage with Istanbul and Karma
  • End-to-end Angular 2 code using Protractor.
  • Type manager with tsd

Prerequisites

You will need the following things properly installed on your computer.

  • Git
  • Node.js (with NPM) Ensure you're running the latest versions Node v4.1.x+ and NPM 2.14.x+
  • PhantomJS
  • typescript (npm install --global typescript)

Quick start

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

# clone our repo
git clone https://github.com/mattma/angular2-rocks

# change directory to our repo
cd angular2-rocks

# install the repo with npm
npm install

# start the server
npm start

# go to `http://localhost:4200` in your browser
open http://localhost:4200

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/
 ├──src/                       * source files that will be compiled to javascript
 |   ├──main.ts                * entry file for our browser environment
 │   │
 |   ├──index.html             * Index.html: where we generate our index page
 │   │
 |   ├──vendor.ts              * vendor file
 │   │
 │   ├──app/                   * WebApp: folder
 │   │   ├──app.spec.ts        * a simple test of components in app.ts
 │   │   └──app.ts             * a simple version of our App component
 │   │
 │   └──assets/                * static assets are served here
 │       ├──service-worker.js  * ignore this. Web App service worker that's not complete yet
 │       ├──robots.txt         * for search engines to crawl your website
 │       └──human.txt          * for humans to know who the developers are
 │
 ├──test/                      * global unit tests and end-to-end tests
 │
 ├──spec-bundle.js             * ignore this magic that sets up our angular 2 testing environment
 ├──karma.config.js            * karma config for our unit tests
 ├──protractor.config.js       * protractor config for our end-to-end tests
 │
 ├──tsconfig.json              * config that webpack uses for typescript
 ├──tsd.json                   * typings manager
 ├──package.json               * what npm uses to manage it's dependencies
 │
 ├──webpack.config.js          * development webpack config
 ├──webpack.test.config.js     * testing webpack config
 └──webpack.prod.config.js     * production webpack config

Libraries

The benefit of using immutable data is that dirty checking does not need to perform a deep equality check. If every mutation returns a new object, dirty checking can use a blazingly fast strict equality check

Scripts

server

npm start # alias: npm run server:dev
npm run server # (default: dev)
npm run server:dev
npm run server:prod

It starts 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:4200 (or if you prefer IPv6, if you're using express server, then it's http://[::1]:4200/).

build

npm run build # (default: prod)
npm run build:dev
npm run build:prod

When build command is run, it will auto trigger an clean method to remove existing dist folder, so it will make sure that it always have up-to-date build files.

watch

npm run watch # (default: dev)
npm run watch:dev
npm run watch:prod

tests

npm run test
npm run e2e
npm run ci # run both e2e and test

make sure you have webdriver running and a sever for the client app before you run e2e tests.

webdriver scripts can be used for end-to-end.

npm run webdriver:update
npm run webdriver:start

clean

npm run clean
npm run clean:dist

lint

npm run lint

tsd

npm run tsd
npm run tsd:clean

doc

npm run doc

It will generate the documenation of the current application via typedoc.

TypeScript

To take full advantage of TypeScript with autocomplete you would have to install it globally and use an editor with the correct TypeScript plugins.

TypeScript 1.7.x includes everything you need. Make sure to upgrade, even if you installed TypeScript previously. Do now npm install --global typescript.

Frequently asked questions

  • What's the current browser support for Angular 2 Beta?

  • Why is my service, aka provider, is not injecting parameter correctly?

    • Please use @Injectable() for your service for typescript to correctly attach the metadata (this is a TypeScript problem)
  • How do I start the app when I get EACCES and EADDRINUSE errors?

    • The EADDRINUSE error means the port 3000 is currently being used and EACCES is lack of permission for webpack to build files to ./dist/
  • How to use sass for css?

  • loaders: ['raw-loader','sass-loader'] and @Component({ styles: [ require('./filename.scss') ] }) see issue #136

  • How do I test a Service?

  • See issue #130

  • How do I make the repo work in a virtual machine?

    • You need to use 0.0.0.0 so revert these changes #205
  • What are the naming conventions for Angular 2?

  • please see issue #185 and PR 196

Other Seed/Starter/Example Repos

Resources

Blog

Video

Post

Projects

  • projects to checkout
  • [angular-cli] npm install -g angular-cli@latest to install
  • ng2Boilerplate
  • projects with code samples

Plugins Projects

Thanks

Special thanks to those projects to inspire angular2-rocks.

TODO

  1. Add tsconfig
{
  "compilerOptions": {
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

License

Copyright (c) 2016 Matt Ma

Angular2 Rocks is MIT Licensed.

angular2-rocks's People

Contributors

mattma avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.