-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
126 lines (114 loc) · 3.27 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var gulp = require('gulp');
var concat = require('gulp-concat');
var del = require('del');
var gulpif = require('gulp-if');
var wrap = require('gulp-wrap');
var htmlmin = require('gulp-htmlmin');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var sourcemaps = require('gulp-sourcemaps');
var templateCache = require('gulp-angular-templatecache');
var path= require('path');
var sass = require('gulp-sass');
var server = require('browser-sync');
var yargs = require('yargs');
var historyApiFallback = require('connect-history-api-fallback');
var autoprefixer = require('gulp-autoprefixer');
server.create();
const argv = yargs.argv;
const root = 'src/';
const paths = {
dist: 'docs/',
scripts: [`${root}/**/module.js`, `${root}/**/*.js`],
styles: `${root}/scss/**/*.scss`,
templates: `${root}/**/*.html`,
modules: [
'angular/angular.js',
'angular-animate/angular-animate.js',
'angular-ui-router/release/angular-ui-router.js',
'angular-translate/dist/angular-translate.js',
'angular-loading-bar/build/loading-bar.min.js',
'angularjs-slider/dist/rzslider.js',
'ng-dialog/js/ngDialog.js',
'firebase/firebase.js',
'angularfire/dist/angularfire.js',
'chart.js/dist/Chart.js',
'angular-chart.js/dist/angular-chart.js',
'easy-pie-chart/dist/angular.easypiechart.js'
],
static: [
`${root}/index.html`,
`${root}/img/**/*`,
`${root}/data/**/*`,
`${root}/.htaccess`,
]
};
gulp.task('clean', cb => del(paths.dist + '**/*', {force: true}, cb));
gulp.task('templates', () => {
return gulp.src(paths.templates)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(templateCache({
root: 'app',
standalone: true,
transformUrl: function (url) {
return url.replace('app/', '');
}
}))
.pipe(gulp.dest('./'));
});
gulp.task('modules', ['templates'], () => {
return gulp.src(paths.modules.map(item => 'node_modules/' + item))
.pipe(concat('vendor.js'))
.pipe(gulpif(argv.deploy, uglify()))
.pipe(gulp.dest(paths.dist + 'js/'));
});
gulp.task('styles', () => {
return gulp.src(paths.styles)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}))
.pipe(autoprefixer({
browsers: ['last 4 versions']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.dist + 'css/'));
});
gulp.task('scripts', ['modules'], () => {
return gulp.src([
...paths.scripts,
'./templates.js'
])
.pipe(wrap('(function(angular){\n\'use strict\';\n<%= contents %>})(window.angular);'))
.pipe(concat('bundle.js'))
.pipe(ngAnnotate())
.pipe(gulpif(argv.deploy, uglify()))
.pipe(gulp.dest(paths.dist + 'js/'));
});
gulp.task('serve', () => {
return server.init({
files: [`${paths.dist}/**`],
port: 4000,
server: {
baseDir: paths.dist,
middleware: [ historyApiFallback()]
}
});
});
gulp.task('copy', ['clean'], () => {
return gulp.src(paths.static, { base: 'src' })
.pipe(gulp.dest(paths.dist));
});
gulp.task('watch', ['serve', 'scripts'], () => {
gulp.watch([paths.scripts, paths.templates], ['scripts']);
gulp.watch(paths.styles, ['styles']);
});
gulp.task('default', [
'copy',
'styles',
'serve',
'watch'
]);
gulp.task('production', [
'copy',
'styles',
'scripts'
]);