Giter VIP home page Giter VIP logo

angularjs-starter-pack's Introduction

angularjs-starter-pack

A simple template including Gulp, JSPM, ES6 & AngularJS 1.4 to stop dealing with boring stuff and start coding quickly.


Requirements

  1. Node.js

Setup

  1. Fork & clone this repos
  2. Go to the project directory
  3. npm install
  4. gulp serve
  5. Go to localhost:4000
  6. That's it, you're ready to code!

This template comes with

  • Gulp workflow
  • ES6 with on-the-fly transpilation (using Babel) in development
  • AngularJS 1.4 starter app
  • Bundling transpiled JS for prodution
  • JSPM
  • SASS

The AngularJS starter app works by default with

  • ui-router
  • lodash
  • angular-bootstrap
  • A ready to go config module to set all your env variables
  • A ready to go API service to handle API requests quickly & properly
  • A ready to go express server for production environment

Documentation

Files organization & best-practices

Todo

Gulp tasks

Todo

JSPM

Todo

ES6 syntax

Todo

config module

The src/app/config.js module is generated by a gulp task, do not update it because it will be erased each time you run gulp serve.

In order to use environment variables in your project, you need to create a .env.json file in the project root directory. Then, for each variable, you simply need to add it in gulp/config.js (there are already 3 variables used by the API service).

Gulp will create a CONFIG module for you AngularJS app and store all your environment variables as constants inside, then, you'll be able to use them like that:

angular
  .module('myModule', [])
  .controller('MyController', [
    'CONFIG',
    (CONFIG) => {
      const myApiUrl = `${CONFIG.API_URL}/${CONFIG.API_VERSION}`;
    }
  ]);

API service

Configuration

In order to use the API service, you have to set your API url & version in a environment file.

  • First, in the project root directory, create a .env.json file (it's already added in the .gitignore).
  • Then, add an object with these two variables in the environment file:
  {
   "API_URL": "http://localhost:3000",
   "API_VERSION": "v1"
  }

That's it! The API service will find these variables thanks to the CONFIG module it takes in dependency and use it for all your API calls.

Usage

Add API as a dependency in all the modules you want to use it. 5 methods are available for this module, they represent the 5 HTTP methods for RESTful APIs.

  API.get('/url', {})
  API.post('/url', {})
  API.put('/url', {})
  API.patch('/url', {})
  API.delete('/url')

Each of these methods returns a promise with the resolved data. There is a full example:

angular
  .module('myModule', [])
  .controller('MyModuleController', [
    'API',
    class {
      constructor(API) {
        API.get('/users').then((res) => {
          console.log(res.data.users);
        });
      }
    }
  ]);

express server for production

Todo

Deploy to heroku

Todo

Author

Anthony Mangiavellano [email protected].

License

WTFPL. http://www.wtfpl.net/

angularjs-starter-pack's People

Contributors

mangiavellano avatar

Watchers

James Cloos avatar Valentine Pierres 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.