-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
94 lines (83 loc) · 2.65 KB
/
Copy pathgulpfile.js
File metadata and controls
94 lines (83 loc) · 2.65 KB
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
const gulp = require('gulp');
const sass = require('gulp-sass');
const sassBundler = require('gulp-sass-bundler');
const clean = require('gulp-clean');
const replace = require('gulp-replace');
const watch = require('gulp-watch');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const minify = require('gulp-minify');
const sassInput = './server/views/raw/sass';
const jsInput = './server/views/raw/scripts/bundle.js';
const sassOutput = './server/views/raw/bundle';
const cssOutput = './server/public/styles/bundle';
const jsOutput = './server/public/scripts';
var hash = '';
gulp.task('jsMin', ['clean-js', 'scripts-templates'], function () {
gulp.src(jsInput)
.pipe(minify({
ext: {
src: `.${hash}.debug.js`,
min: `.${hash}.js`
},
exclude: ['tasks'],
ignoreFiles: ['.combo.js', '-min.js']
}))
.pipe(gulp.dest(jsOutput));
});
gulp.task('clean-js', function () {
gulp.src(`${jsOutput}/*`, {read: false})
.pipe(clean());
});
gulp.task('scripts-templates', function () {
gulp.src(['./server/views/layout/scripts.pug'])
.pipe(replace(/bundle.[0-9]{1,10}.js/, `bundle.${hash}.js`))
.pipe(gulp.dest('./server/views/layout'));
});
gulp.task('sass', ['clean-sass', 'clean-css', 'bundle-sass', 'styles-templates'], function () {
const sassOptions = {
errLogToConsole: true,
outputStyle: 'compressed'
};
const autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
gulp
.src(`./server/views/raw/bundle/bundle.${hash}.scss`)
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourcemaps.write(`bundle.${hash}.map.css`))
.pipe(gulp.dest(cssOutput));
});
gulp.task('bundle-sass', function () {
sassBundler({
dirs: [
{path: `${sassInput}/loader.scss`, depth: -1}
],
targetImportsFolder: sassOutput,
targetImportsFile: `bundle.${hash}.scss`,
debug: true
});
});
gulp.task('clean-sass', function () {
gulp.src(`${sassOutput}/*`, {read: false})
.pipe(clean());
});
gulp.task('clean-css', function () {
gulp.src(`${cssOutput}/*`, {read: false})
.pipe(clean());
});
gulp.task('styles-templates', function () {
gulp.src(['./server/views/layout/styles.pug'])
.pipe(replace(/bundle.[0-9]{1,10}.css/, `bundle.${hash}.css`))
.pipe(gulp.dest('./server/views/layout'));
});
gulp.task('watch', function () {
gulp.watch(`${sassInput}/**/*.scss`, ['prod']);
gulp.watch(jsInput, ['prod']);
});
gulp.task('hash', function () {
hash = Date.now() / 1000 | 0;
});
gulp.task('prod', ['hash', 'sass', 'jsMin']);