-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathgulpfile.js
78 lines (69 loc) · 3.07 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
var gulp = require('gulp'),
sass = require('gulp-sass')(require('node-sass')),
sourcemaps = require('gulp-sourcemaps'),
cleanCss = require('gulp-clean-css'),
rename = require('gulp-rename'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
concatCss = require('gulp-concat-css');
gulp.task('build-theme', function () {
return gulp.src(['scss/bootstrap-*.scss', 'scss/toggle-*.scss'])
.pipe(sourcemaps.init())
.pipe(sass({ includePaths: [__dirname] }).on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/css/'))
.pipe(cleanCss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css/'))
});
gulp.task('clean-prefers-stylesheets', function () {
const cleanNonColorAttr = require("./clean_non_color_attr.js");
return gulp.src(['dist/css/bootstrap-prefers-dark.css', 'dist/css/bootstrap-prefers-light.css'])
.pipe(cleanNonColorAttr({ compress: false }))
.pipe(cleanCss({ format: "beautify" }))
.pipe(rename({ suffix: '-color-only' }))
.pipe(gulp.dest('dist/css'));
});
gulp.task('combine-prefers-stylesheets', gulp.parallel(
function () { return combinePrefersStylesheet("dark", "light"); },
function () { return combinePrefersStylesheet("light", "dark"); }
));
gulp.task('build-combined-theme', gulp.series('clean-prefers-stylesheets', 'combine-prefers-stylesheets'));
function combinePrefersStylesheet(defaultThemeName, prefersThemeName) {
return gulp.src([`dist/css/bootstrap-${defaultThemeName}.css`, `dist/css/bootstrap-prefers-${prefersThemeName}-color-only.css`])
.pipe(cleanCss({ format: "beautify" }))
.pipe(concatCss(`bootstrap-${defaultThemeName}-prefers-${prefersThemeName}.css`))
// .pipe(sourcemaps.init())
// .pipe(sass({ includePaths: [__dirname] }).on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
// .pipe(sourcemaps.write())
.pipe(gulp.dest('dist/css/'))
.pipe(cleanCss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css/'))
;
}
gulp.task('copy-bootstrap-js', function () {
return gulp
.src(['node_modules/bootstrap/dist/js/*'])
.pipe(gulp.dest('dist/js/'));
});
gulp.task('copy-dist-to-razor-pages', function () {
return gulp
.src(['dist/**/*'])
.pipe(gulp.dest('samples/razor-pages/wwwroot/'));
});
gulp.task('copy-dist-to-html', function () {
return gulp
.src(['dist/**/*'])
.pipe(gulp.dest('samples/html/'));
});
gulp.task('copy-dist-to-samples', gulp.parallel(
'copy-dist-to-razor-pages',
'copy-dist-to-html'
));
gulp.task('watch', gulp.series(gulp.parallel('copy-bootstrap-js', gulp.series('build-theme', 'build-combined-theme', 'copy-dist-to-samples')), function () {
gulp.watch(['scss/*.scss'], gulp.series('build-theme', 'copy-dist-to-samples'));
}));
gulp.task('default', gulp.parallel('copy-bootstrap-js', gulp.series('build-theme', 'build-combined-theme', 'copy-dist-to-samples')));