Skip to content

Instantly share code, notes, and snippets.

@dhoko
Last active May 29, 2017 03:37
Show Gist options
  • Select an option

  • Save dhoko/c14534be5e0a99b89709 to your computer and use it in GitHub Desktop.

Select an option

Save dhoko/c14534be5e0a99b89709 to your computer and use it in GitHub Desktop.
Minimal setup for Gulp and Angular

Minimal setup for Gulp and Angular

Included

  • Gulp
  • Concat your files
  • ng-Annotate ( Add, remove and rebuild AngularJS dependency injection annotations )
  • Minification
  • Sourcemaps

Requirements

  • nodejs + npm

Install

With package.json

$ npm install

Without package.json

$ npm install --save-dev gulp && npm install --save-dev gulp-concat && npm install --save-dev gulp-ng-annotate && npm install --save-dev gulp-rename && npm install --save-dev gulp-sourcemaps && npm install --save-dev gulp-uglify

Explanation

.
├── GulpFile.js
├── package.json
├── src/
    ├── index.js // Module declaration
    ├── providers/ Store your providers
    ├── services/ Your services
    └── etc.
└── dist/ // Build
    ├── script.js // Concat of src/**/*.js with sourcemaps
    └── script.min.js // Without sourcemaps

Ex

A module

angular.module('myModule', [])
    .run(function (hello) {
        'use strict';
        hello.world();
    });

A service

angular.module('myModule')
    .service('hello', function () {
        'use strict';

         var service = {};

         service.world = function world() {
              return 'Hello World';
         };

         return service;
    });
'use strict';
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
ngAnnotate = require('gulp-ng-annotate'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function() {
gulp.src('./src/**/*.js')
.pipe(sourcemaps.init())
.pipe(ngAnnotate({
add: true,
remove: true,
single_quotes: true
}))
.pipe(concat('script.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.pipe(rename('script.min.js'))
.pipe(gulp.dest('./dist/'));
});
{ "name": "ngSetupGulp",
"version": "1.0.0",
"description": "Angular with gulp",
"main": "GulpFile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "contact <contact@contact.fr>",
"license": "MIT",
"devDependencies": {
"gulp": "^3.8.7",
"gulp-concat": "^2.3.4",
"gulp-ng-annotate": "^0.3.0",
"gulp-rename": "^1.2.0",
"gulp-sourcemaps": "^1.1.1",
"gulp-uglify": "^0.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment