-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
134 lines (113 loc) · 5.08 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
////////////////////////////////////////////////////////////////////////////////
// Gulp plugins
////////////////////////////////////////////////////////////////////////////////
const gulp = require('gulp'),
gulpif = require('gulp-if'),
csso = require('gulp-csso'),
sass = require('gulp-sass'),
clean = require('gulp-clean'),
babel = require('gulp-babel'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
htmlmin = require('gulp-htmlmin'),
plumber = require('gulp-plumber'),
nunjucks = require('gulp-nunjucks'),
sequence = require('gulp-sequence'),
decomment = require('gulp-decomment'),
removeLogs = require('gulp-removelogs'),
sourcemaps = require('gulp-sourcemaps'),
special = require('gulp-special-html'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync').create(),
stripCssComments = require('gulp-strip-css-comments');
////////////////////////////////////////////////////////////////////////////////
// Enviroment (available options: dev, prod)
////////////////////////////////////////////////////////////////////////////////
let env = { state: 'dev' };
env.ext = env.state === 'prod' ? '.min' : '';
env.isProd = Boolean(env.state === 'prod');
////////////////////////////////////////////////////////////////////////////////
// Server
////////////////////////////////////////////////////////////////////////////////
gulp.task('start_server', () => browserSync.init({
logPrefix: 'Innatus',
host: 'localhost',
server: {
baseDir: './'
},
browser: [
'google chrome'
],
}));
////////////////////////////////////////////////////////////////////////////////
// views task
////////////////////////////////////////////////////////////////////////////////
gulp.task('html', () => gulp.src(['./build/views/*.html', '!./build/views/_*.html'])
.pipe(nunjucks.compile(require('./build/data/texts.json')))
.pipe(plumber())
.pipe(htmlmin())
.pipe(special())
.pipe(gulp.dest('./'))
.pipe(browserSync.stream())
);
gulp.task('delete_views', () => gulp.src('./*.html').pipe(clean()));
gulp.task('build_views', (callback) => sequence('html')(callback));
gulp.task('watch_views', () => gulp.watch('./build/views/**/*.html', ['build_views']));
////////////////////////////////////////////////////////////////////////////////
// styles task
////////////////////////////////////////////////////////////////////////////////
gulp.task('sass', () => gulp.src(['./build/styles/**/*.scss', '!./build/styles/**/_*.scss'])
.pipe(plumber())
.pipe(concat('styles.css'))
// .pipe(gulpif(!env.isProd, sourcemaps.init(options.sourcemaps)))
.pipe(stripCssComments())
.pipe(autoprefixer())
.pipe(csso())
.pipe(sass())
// .pipe(gulpif(!env.isProd, sourcemaps.write('')))
.pipe(gulp.dest('./public/styles/'))
.pipe(browserSync.stream())
);
gulp.task('delete_styles', () => gulp.src('./public/styles').pipe(clean()));
gulp.task('build_styles', (callback) => sequence('sass')(callback));
gulp.task('watch_styles', () => gulp.watch('./build/styles/**/*.scss', ['build_styles']));
////////////////////////////////////////////////////////////////////////////////
// scripts task
////////////////////////////////////////////////////////////////////////////////
gulp.task('babel', () => gulp.src(['./build/scripts/*.js', '!./build/scripts/_*.js'])
.pipe(plumber())
.pipe(concat('scripts.js'))
// .pipe(gulpif(!env.isProd, sourcemaps.init(options.sourcemaps)))
.pipe(babel({ presets: ['es2015', 'es2016', 'es2017'] }))
.pipe(decomment())
.pipe(uglify())
// .pipe(gulpif(!env.isProd, sourcemaps.write('')))
.pipe(gulp.dest('./build/scripts/temp/'))
.pipe(browserSync.stream())
);
gulp.task('delete_scripts', () => gulp.src(['./build/scripts/temp', './public/scripts']).pipe(clean()));
gulp.task('build_scripts', (callback) => sequence('babel')(callback));
gulp.task('watch_scripts', () => gulp.watch('./build/scripts/**/*.js', ['build_scripts']));
////////////////////////////////////////////////////////////////////////////////
// Watches task
////////////////////////////////////////////////////////////////////////////////
gulp.task('watch', sequence(['watch_scripts', 'watch_styles', 'watch_views']));
////////////////////////////////////////////////////////////////////////////////
// Reset task
////////////////////////////////////////////////////////////////////////////////
gulp.task('reset_app', () => gulp.src([
'./public/styles',
'./public/scripts',
]).pipe(clean()));
////////////////////////////////////////////////////////////////////////////////
// Compilers
////////////////////////////////////////////////////////////////////////////////
gulp.task('server', sequence('watch', 'start_server'));
gulp.task('compile', sequence(
'reset_app',
'build_views',
'build_styles',
'build_scripts'
));
gulp.task('start', sequence('compile', 'server'));