-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
133 lines (116 loc) · 3.61 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
127
128
129
130
131
132
133
/* libs */
var gulp = require('gulp');
var gutil = require('gulp-util');
var ignore = require('gulp-ignore');
var runSequence = require('run-sequence');
var $ = require('gulp-load-plugins')();
var lazypipe = require('lazypipe');
var del = require('del');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var nunjucksRender = require('gulp-nunjucks-render');
var sass = require('gulp-sass');
var argv = require('yargs').argv;
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*'],
replaceString: /\bgulp[\-.]/
});
/* vars */
var appPath = './src';
var distPath = './dist/';
var sassSrc = appPath + '/styles/*.scss';
var sassDist = distPath + '/css/';
var jsSrc = appPath + '/js/*.js';
var jsDist = distPath + '/js/';
var templatesSrc = appPath + '/templates/';
var partialsSrc = templatesSrc + '/partials/';
var pagesPath = appPath + '/pages/**/*.nunjucks';
var pagesDist = distPath;
var config = {
defaultPort: 3000,
supportedBrowsers: [
'ie >= 9',
'last 1 Firefox versions',
'last 1 Chrome versions',
'Safari >= 6',
'iOS >= 6',
'ChromeAndroid >= 4.2'
],
version: require('./package.json').version,
minify: argv.minify || false
};
// Clean site directory
gulp.task('clean', del.bind(null, [distPath], {dot: true}));
gulp.task('styles', function() {
gulp.src(sassSrc)
.pipe(sourcemaps.init()) // Initialize sourcemap plugin
.pipe(sass())
.pipe(autoprefixer()) // Passes it through gulp-autoprefixer
.pipe(sourcemaps.write()) // Writing sourcemaps
.pipe(gulp.dest(sassDist)) // Outputs it in the css folder
// Reloading the stream
.pipe(browserSync.reload({
stream: true
}));
});
var scriptsFinish = lazypipe()
.pipe(gulp.dest, jsDist)
.pipe(function () {
return $.if(config.minify, $.uglify());
})
.pipe(function () {
return $.if(config.minify, $.rename({suffix: '.min'}));
})
.pipe(function () {
return $.if(config.minify, gulp.dest(jsDist));
});
// Lint and build scripts
gulp.task('scripts', function() {
return gulp.src(jsSrc)
.pipe($.plumber({errorHandler: $.notify.onError('Error: <%= error.message %>')}))
.pipe($.if(config.isWatching, $.jshint()))
.pipe($.if(config.isWatching, $.jshint.reporter('jshint-stylish')))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')))
.pipe($.concat('scripts.js'))
.pipe(scriptsFinish());
});
gulp.task('nunjucks', function() {
// Gets .html and .nunjucks files in pages
return gulp.src(pagesPath)
// Renders template with nunjucks
.pipe(nunjucksRender({
path: [templatesSrc]
}))
// output files in app folder
.pipe(gulp.dest(pagesDist))
});
gulp.task('setWatch', function() {
config.isWatching = true;
});
// Development task
gulp.task('dev', ['default', 'setWatch'], function() {
browserSync({
port: argv.port || config.defaultPort, //default: 3000
server: { baseDir: distPath},
ui: {
port: argv.port + 5000 || config.defaultPort + 5000, //default: 8000
weinre: { port: argv.port + 6092 || config.defaultPort + 6092 } //default: 9092
},
notify: false,
logLevel: 'silent' //other oprions: info, debug
});
gulp.watch([sassSrc], ['styles', reload]);
gulp.watch([templatesSrc + '**/*.nunjucks'], ['nunjucks', reload]);
gulp.watch([pagesPath], ['nunjucks', reload]);
gulp.watch([jsSrc], ['scripts', reload]);
});
// Build production files, the default task
gulp.task('default', ['clean'], function (cb) {
runSequence([
'styles',
'scripts',
'nunjucks'
], cb);
});