This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
executable file
·124 lines (108 loc) · 3.28 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
/* eslint-disable import/no-extraneous-dependencies */
const gulp = require('gulp');
const sass = require('gulp-sass');
const scsslint = require('gulp-scss-lint');
const beautify = require('gulp-beautify');
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const minifyCss = require('gulp-minify-css');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();
const pkg = require('./package.json');
const nunjucksRender = require('gulp-nunjucks-render');
const reloadBrowser = (done) => {
browserSync.reload();
done();
};
gulp.task('scss:copy', () =>
gulp.src(['src/scss/**/*.scss'])
.pipe(gulp.dest('dist'))
);
gulp.task('scss', ['scss:copy'], () =>
gulp.src('dist/main.scss')
.pipe(rename(`_${pkg.name}.scss`))
.pipe(gulp.dest('dist'))
);
gulp.task('css', () =>
gulp.src('src/scss/main.scss')
.pipe(
sass({
errLogToConsole: true,
includePaths: ['./node_modules'],
outputStyle: 'nested',
}).on('error', sass.logError)
)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false,
}))
.pipe(rename(`${pkg.name}.css`))
.pipe(gulp.dest('dist'))
.pipe(minifyCss())
.pipe(rename(`${pkg.name}.min.css`))
.pipe(gulp.dest('dist'))
);
gulp.task('scss:lint-base', () =>
gulp.src(['src/scss/**/*.scss'])
.pipe(scsslint({
maxBuffer: 1000000,
reporterOutput: 'scss-report.json',
}))
);
gulp.task('scss:lint-with-report', () =>
gulp.src('scss-report.json')
.pipe(beautify())
.pipe(gulp.dest('.'))
);
gulp.task('scss:lint', () => ['scss:lint-base', 'scss:lint-with-report']);
gulp.task('example-css', () =>
gulp.src('example/src/scss/main.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
errLogToConsole: true,
includePaths: ['./node_modules'],
outputStyle: 'nested',
}).on('error', sass.logError)
)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false,
}))
.pipe(rename('bundle.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('example/build'))
.pipe(browserSync.stream())
);
gulp.task('example-js', () =>
gulp.src('example/src/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('example/build'))
);
gulp.task('example-html', () =>
gulp.src('example/src/views/pages/**/*.nunjucks')
.pipe(nunjucksRender({ path: ['example/src/views'] }))
.pipe(gulp.dest('example/'))
);
// high level tasks
gulp.task('example', ['example-css', 'example-js', 'example-html']);
gulp.task('compile', ['css', 'scss', 'example']);
// default task
gulp.task('default', ['compile']);
// watch tasks
gulp.task('example-js-watch', ['example-js'], reloadBrowser);
gulp.task('example-html-watch', ['example-html'], reloadBrowser);
gulp.task('serve', ['example'], () => {
browserSync.init({
notify: true,
server: './example',
});
gulp.watch(['example/src/scss/**/*.scss', 'src/scss/**/*.scss'], ['example-css']);
gulp.watch(['example/src/js/**/*.js'], ['example-js-watch']);
gulp.watch(['example/src/views/**/*.nunjucks'], ['example-html-watch']);
});