A simple template including Gulp, JSPM, ES6 & AngularJS 1.4 to stop dealing with boring stuff and start coding quickly.
- Requirements
- Setup
- What contains this starter pack?
- Included modules & addons
- Documentation
- Author
- License
- Fork & clone this repos
- Go to the project directory
npm install
gulp serve
- Go to
localhost:4000
- That's it, you're ready to code!
- Gulp workflow
- ES6 with on-the-fly transpilation (using Babel) in development
- AngularJS 1.4 starter app
- Bundling transpiled JS for prodution
- JSPM
- SASS
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
Todo
Todo
Todo
Todo
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}`;
}
]);
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.
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);
});
}
}
]);
Todo
Todo
Anthony Mangiavellano mangiavellano.anthony@gmail.com.
WTFPL. http://www.wtfpl.net/