-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
133 lines (117 loc) · 4.17 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
////////////////////////////////
//Setup//
////////////////////////////////
// Plugins
var gulp = require('gulp'),
pjson = require('./package.json'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
del = require('del'),
plumber = require('gulp-plumber'),
pixrem = require('gulp-pixrem'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
exec = require('child_process').exec,
runSequence = require('run-sequence'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
concat = require('gulp-concat'),
debug = require('gulp-debug'),
spawn = require('child_process').spawn;
sourcemaps = require('gulp-sourcemaps');
// Relative paths function
var pathsConfig = function (appName) {
this.app = "./" + (appName || pjson.name);
this.python = pythonPath = process.env.VIRTUAL_ENV || process.env.PWD || "/usr/local/lib/python2.7/";
return {
app: this.app,
templates: this.app + '/templates',
assets: {
js: this.app + '/assets/js',
images: this.app + '/assets/images',
sass: this.app + '/assets/sass',
fonts: this.app + '/assets/fonts'
},
js: this.app + '/static/js',
images: this.app + '/static/images',
css: this.app + '/static/css',
fonts: this.app + '/static/fonts',
vendor_js: [
'node_modules/jquery/jquery.js',
'node_modules/popper.js/dist/umd/popper.js',
'node_modules/qrious/dist/qrious.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/conditionizr/dist/conditionizr.js',
'node_modules/conditionizr/detects/chrome.js',
'node_modules/conditionizr/detects/chromium.js'
]
}
};
var paths = pathsConfig();
////////////////////////////////
//Tasks//
////////////////////////////////
// Styles autoprefixing and minification
gulp.task('styles', function () {
return gulp.src(paths.assets.sass + '/*.scss')
.pipe(plumber()) // Checks for errors
.pipe(sass({includePaths: ['node_modules']}))
.pipe(autoprefixer()) // Adds vendor prefixes
.pipe(pixrem()) // add fallbacks for rem units
.pipe(browserSync.stream())
.pipe(gulp.dest(paths.css))
.pipe(rename({suffix: '.min'}))
.pipe(cssnano()) // Minifies the result
.pipe(gulp.dest(paths.css))
.pipe(browserSync.stream())
.pipe(debug());
});
// Javascript minification
gulp.task('scripts', function () {
gulp.src([paths.assets.js].concat(paths.vendor_js))
.pipe(plumber()) // Checks for errors
.pipe(sourcemaps.init())
.pipe(concat('project.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.js))
.pipe(rename({suffix: '.min'}))
.pipe(uglify()) // Minifies the js
.pipe(gulp.dest(paths.js))
.pipe(browserSync.stream());
});
// Image compression
gulp.task('imgCompression', function () {
return gulp.src(paths.assets.images + '/*')
.pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images
.pipe(gulp.dest(paths.images))
});
// Browser sync server for live reload
gulp.task('browserSync', function () {
browserSync.init({
proxy: "https://localhost:8000",
https: true
});
});
// Run django server
gulp.task('runServer', function() {
spawn('python', ['manage.py', 'runserver_plus', '--cert', '/tmp/ssl'], { stdio: 'inherit' })
});
// Default task
gulp.task('default', function () {
runSequence(['styles', 'scripts', 'imgCompression'],
'runServer',
'browserSync');
});
////////////////////////////////
//Watch//
////////////////////////////////
// Watch
gulp.task('watch', ['default'], function () {
gulp.watch(paths.assets.sass + '/*.scss', ['styles']);
gulp.watch(paths.assets.js + '/*.js', ['scripts']).on("change", reload);
gulp.watch(paths.assets.images + '/*', ['imgCompression']);
gulp.watch(paths.templates + '/**/*.html').on("change", reload);
});