forked from python-spain/web-pycones
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
134 lines (118 loc) · 3.58 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
134
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var rename = require("gulp-rename");
var imagemin = require('gulp-imagemin');
var cssnano = require('gulp-cssnano');
var pixrem = require('gulp-pixrem');
var babel = require('gulp-babel');
var browserify = require('gulp-browserify');
var config = require('./package.json');
// Helper for handle static paths
// -----------------------------------------------------------------------------
var pathsConfig = function(appName) {
var app = appName || config.name;
return {
app: app,
templates: app + '/templates',
base: app + '/static',
sass: app + '/static/sass',
css: app + '/static/css',
fonts: app + '/static/fonts',
images: app + '/static/images',
js: app + '/static/js',
manageScript: app + 'manage.py'
}
};
// CSS Task
// -----------------------------------------------------------------------------
var cssTask = function(options) {
// Default include node_modules to SASS include paths
var sassOptions = {
includePaths: ['./node_modules/'],
errLogToConsole: true
};
// Common 'run' code for each options
var run = function(options) {
options = sassOptions || options;
gulp.src(pathsConfig().sass + '/pydaygal.scss')
.pipe(sass(options).on('error', sass.logError))
.pipe(autoprefixer({ browsers: ['last 2 version'] }))
.pipe(pixrem())
.pipe(gulp.dest(pathsConfig().css))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano())
.pipe(gulp.dest(pathsConfig().css));
};
// Run for development with watch
if (options.development) {
run();
gulp.watch(options.watch, run);
// Run for production with compressed
} else {
run({ outputStyle: 'compressed' });
}
};
// Images Task
// -----------------------------------------------------------------------------
var imagesTask = function(options) {
var run = function() {
gulp.src(pathsConfig().images + '/**/*')
.pipe(imagemin())
.pipe(gulp.dest(pathsConfig().images));
};
if (options.development) {
run();
gulp.watch(options.watch, run);
} else {
run();
}
};
// App Task
// -----------------------------------------------------------------------------
var appTask = function(options) {
var run = function() {
gulp.src(pathsConfig().js + '/src/*.js')
.pipe(babel({ presets: ['es2015'] }))
.pipe(browserify({ insertGlobals: true }))
.pipe(rename('bundle.js'))
.pipe(gulp.dest(pathsConfig().js + '/bin'));
};
if (options.development) {
run();
gulp.watch(options.watch, run);
} else {
run();
}
};
// Default Task
// -----------------------------------------------------------------------------
// Starts our development workflow
gulp.task('default', function() {
cssTask({
watch: pathsConfig().sass + "/**/*.scss",
development: true
});
imagesTask({
development: true,
watch: pathsConfig().images + "/**/*"
});
appTask({
development: true,
watch: pathsConfig().js + "/src/**/*"
});
});
// Build Task
// -----------------------------------------------------------------------------
gulp.task('build', function() {
cssTask({
development: false
});
imagesTask({
development: false
});
appTask({
development: false
});
});