forked from GSA/10x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (96 loc) · 3.05 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
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var del = require('del');
var gulp = require('gulp');
var gzip = require('gulp-gzip');
var movecss = require('css-mqpacker');
var path = require('path');
var postcss = require('gulp-postcss');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var size = require('gulp-size');
var uncss = require('postcss-uncss');
var watch = require('gulp-watch');
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// SETTINGS
// Should we build a font file separate from the main css?
const CONCAT_FONTS = false;
// What modules should be in the final app build?
// Comment out unneeded modules
const USWDS_APP = [
"build-utilities",
// "build-uswds",
"build-custom",
];
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// LOCATIONS
// All locations are relative to the project root
// Don't use a trailing `/` for path names, use `path/to/dir`
// USWDS source directory
const USWDS_SRC = '_vendor/uswds';
// Project Sass source directory
const PROJECT_SASS_SRC = '_sass';
// Asset destination
const ASSETS_DEST = 'assets/uswds';
// CSS destination
const CSS_DEST = 'assets/css';
// Build destination
const BUILD_DEST = '_develop';
// Include destination
const INC_DEST = '_includes';
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// BUILD USWDS STYLES
gulp.task('copy-uswds-assets', () => {
return gulp.src(`${USWDS_SRC}/@(js|fonts|img)/**/**`)
.pipe(gulp.dest(`${ASSETS_DEST}`));
});
gulp.task('clean-css', function () {
return del([
`${CSS_DEST}/**/*`
]);
});
gulp.task('build-sass', ['clean-css'], function (done) {
var plugins = [
autoprefixer({ browsers: ['> 3%', 'Last 2 versions'], cascade: false, }),
movecss({ sort: true }),
cssnano()
];
return gulp.src([
`${PROJECT_SASS_SRC}/*.scss`
])
.pipe(sass({
includePaths: [
`${PROJECT_SASS_SRC}`,
`${USWDS_SRC}/stylesheets`,
]
}))
.pipe(postcss(plugins))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(`${CSS_DEST}`))
.pipe(size())
.pipe(gzip({ extension: 'gz' }))
.pipe(gulp.dest(`${CSS_DEST}`))
.pipe(size());
});
gulp.task('build-app', ['build-sass'], function() {
var plugins = [
uncss({
html: [`${BUILD_DEST}/**/*.html`],
ignore: [/\[aria-/, /is-visible/],
}),
cssnano()
];
return gulp.src(`${CSS_DEST}/10x.min.css`)
.pipe(postcss(plugins))
.pipe(rename('10x.app.min.css'))
.pipe(gulp.dest(`${INC_DEST}`))
.pipe(size())
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gulp.task('watch', ['build-sass'], function (){
gulp.watch(`${PROJECT_SASS_SRC}/*.scss`, ['build-sass'])
gulp.watch(`${USWDS_SRC}/stylesheets/*.scss`, ['build-sass']);
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Set watch as default task
gulp.task('default', ['watch', 'sass', 'copy-uswds-assets']);