-
Notifications
You must be signed in to change notification settings - Fork 52
/
gulpfile.js
153 lines (120 loc) · 3.19 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'use strict';
// IMPORT DEPENDENCIES
const gulp = require('gulp');
const header = require('gulp-header');
const rename = require('gulp-rename');
const plumber = require('gulp-plumber');
const flatten = require('gulp-flatten');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const connect = require('gulp-connect');
// PACKAGE INFO FOR HEADERS
const packageInfo = require('./package.json');
// GLOBAL PATHS
const paths = {
scripts: {
input: 'src/js/*',
output: 'dist/js/'
},
styles: {
input: 'src/scss/**/*.{scss,sass}',
output: 'dist/css/'
},
fonts: {
input: 'src/fonts/*.*',
output: 'dist/fonts/'
},
demoStyles: {
input: 'demoSrc/**/*.{scss,sass}',
output: 'demoDist/'
}
};
// BANNER
const banner = {
full:
`/*!\n <%= package.name %> v<%= package.version %>: <%= package.description %>\n (c) ${new Date().getFullYear()} <%= package.author.name %>\n MIT License\n <%= package.repository.url %>\n*/\n`,
min :
`/*! <%= package.name %> v<%= package.version %> | (c) ${new Date().getFullYear()} <%= package.author.name %> | MIT License | <%= package.repository.url %> */\n`
};
// CSS
gulp.task('css', function() {
gulp.src(paths.styles.input)
.pipe(plumber())
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(flatten())
.pipe(autoprefixer({
browsers: ['last 3 version'],
cascade: true,
remove: true
}))
.pipe(header(banner.full, { package : packageInfo }))
.pipe(gulp.dest(paths.styles.output))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano({
discardComments: {
removeAll: true
}
}))
.pipe(header(banner.min, { package : packageInfo }))
.pipe(gulp.dest(paths.styles.output))
.pipe(connect.reload());
});
// FONTS
gulp.task('fonts', function() {
gulp.src(paths.fonts.input)
.pipe(plumber())
.pipe(gulp.dest(paths.fonts.output))
});
// DEMO CSS
gulp.task('demo-css', function() {
gulp.src(paths.demoStyles.input)
.pipe(plumber())
.pipe(sass())
.pipe(flatten())
.pipe(autoprefixer({
browsers: ['last 3 version'],
cascade: true,
remove: true
}))
.pipe(cssnano({
discardComments: {
removeAll: true
}
}))
.pipe(gulp.dest(paths.demoStyles.output))
.pipe(connect.reload());
});
// JS
gulp.task('js', function () {
return gulp.src(paths.scripts.input)
.pipe(plumber())
.pipe(babel())
.pipe(header(banner.full, { package : packageInfo }))
.pipe(gulp.dest(paths.scripts.output))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(header(banner.min, { package : packageInfo }))
.pipe(gulp.dest(paths.scripts.output))
.pipe(connect.reload());
});
// CONNECT
gulp.task('connect', function() {
connect.server({
port: 3000,
livereload: true
});
});
// WATCH
gulp.task('watch', function() {
gulp.watch(paths.styles.input, ['css']);
gulp.watch(paths.demoStyles.input, ['demo-css']);
gulp.watch(paths.scripts.input, ['js']);
});
// TASKS
gulp.task('default', ['connect', 'css', 'demo-css', 'js', 'fonts', 'watch']);
gulp.task('build', ['css', 'demo-css', 'js']);