forked from ten1seven/what-input
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
178 lines (155 loc) · 3.21 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* load plugins
*/
const pkg = require('./package.json')
const banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n')
// gulp
const gulp = require('gulp')
// load all plugins in "devDependencies" into the letiable $
const $ = require('gulp-load-plugins')({
pattern: ['*'],
scope: ['devDependencies']
})
/*
* clean task
*/
function clean() {
return $.del(['**/.DS_Store', './build/*', './dist/*'])
}
/*
* scripts tasks
*/
function scripts() {
return gulp
.src(['./src/scripts/what-input.js'])
.pipe($.standard())
.pipe(
$.standard.reporter('default', {
breakOnError: false,
quiet: true
})
)
.pipe(
$.webpackStream({
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['env']
}
}
]
},
output: {
chunkFilename: '[name].js',
library: 'whatInput',
libraryTarget: 'umd',
umdNamedDefine: true
}
})
)
.pipe($.rename('what-input.js'))
.pipe($.header(banner, { pkg: pkg }))
.pipe(gulp.dest('./dist/'))
.pipe(gulp.dest('./build/scripts/'))
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe(
$.rename({
suffix: '.min'
})
)
.pipe($.header(banner, { pkg: pkg }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'))
.pipe($.notify('Build complete'))
}
/*
* stylesheets
*/
function styles() {
let processors = [
$.autoprefixer(),
$.cssMqpacker({
sort: true
})
]
return gulp
.src(['./src/styles/index.scss'])
.pipe(
$.plumber({
errorHandler: $.notify.onError('Error: <%= error.message %>')
})
)
.pipe($.sourcemaps.init())
.pipe($.sassGlob())
.pipe($.sass())
.pipe($.postcss(processors))
.pipe(
$.cssnano({
minifySelectors: false,
reduceIdents: false,
zindex: false
})
)
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./build/styles'))
.pipe($.browserSync.stream())
.pipe($.notify('Styles task complete'))
}
/*
* images task
*/
function images() {
return gulp.src(['./src/images/**/*']).pipe(gulp.dest('./build/images'))
}
/*
* markup task
*/
function markup() {
return gulp.src(['./src/markup/*']).pipe(gulp.dest('./build'))
}
/*
* deploy task
*/
function deploy() {
return gulp.src('./build/**/*').pipe($.ghPages())
}
/*
* default task
*/
function watch() {
$.browserSync.init({
server: {
baseDir: './build/'
}
})
gulp.watch(
['./src/scripts/what-input.js', './src/scripts/polyfills/*.js'],
scripts,
{ events: 'all' },
function() {
$.browserSync.reload
}
)
gulp.watch(['./src/styles/{,*/}{,*/}*.scss'], styles)
gulp.watch(['./src/markup/*.html'], markup, { events: 'all' }, function() {
$.browserSync.reload
})
}
exports.default = gulp.series(
clean,
gulp.parallel(markup, scripts, styles, images),
watch
)