forked from Splidejs/splide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
142 lines (129 loc) · 3.08 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
'use strict';
/*
* Dependencies.
*/
const gulp = require( 'gulp' );
const rename = require( 'gulp-rename' );
const sass = require( 'gulp-sass' );
const sassGlob = require( 'gulp-sass-glob' );
const postcss = require( 'gulp-postcss' );
const autoprefixer = require( 'autoprefixer' );
const cssnano = require( 'cssnano' );
const merge = require( 'merge-stream' );
const concat = require( 'gulp-concat' );
const webpack = require( 'webpack' );
const webpackStream = require( 'webpack-stream' );
const eslint = require( 'gulp-eslint' );
const gzip = require( 'gulp-gzip' );
/*
* Webpack config paths.
*/
const js = {
complete: {
path: './build/complete/config',
dest: './dist/js',
},
minified: {
path: './build/complete/config-min',
dest: './dist/js',
gzip: true,
},
modular: {
path: './build/module/config',
dest: './dist/js',
},
};
/*
* Path definitions.
*/
const css = {
all: {
path : './src/sass/core/*.scss',
dest : './dist/css',
merge: {
filename: 'splide.css',
path : './src/sass/themes/default/*.scss',
},
},
core: {
path: './src/sass/core/*.scss',
dest: './dist/css',
},
default: {
path : './src/sass/core/*.scss',
dest : './dist/css/themes',
basename: 'splide-default',
merge : {
filename: 'splide.css',
path : './src/sass/themes/default/*.scss',
},
},
skyblue: {
path : './src/sass/core/*.scss',
dest : './dist/css/themes',
basename: 'splide-skyblue',
merge : {
filename: 'splide.css',
path : './src/sass/themes/sky-blue/*.scss',
},
},
seagreen: {
path : './src/sass/core/*.scss',
dest : './dist/css/themes',
basename: 'splide-sea-green',
merge : {
filename: 'splide.css',
path : './src/sass/themes/sea-green/*.scss',
},
},
};
/*
* Build a script file.
*/
gulp.task( 'build:js', done => {
Object.values( js ).forEach( settings => {
const stream = webpackStream( { config: require( settings.path ) }, webpack )
.pipe( gulp.dest( settings.dest ) );
if ( settings.gzip ) {
stream.pipe( gzip() ).pipe( gulp.dest( settings.dest ) );
}
} );
done();
} );
/*
* Build sass files.
*/
gulp.task( 'build:sass', done => {
Object.values( css ).forEach( settings => {
let stream = gulp.src( settings.path );
if ( settings.merge ) {
stream = merge( stream, gulp.src( settings.merge.path ) )
.pipe( sassGlob() )
.pipe( sass() )
.pipe( concat( settings.merge.filename ) );
}
stream = stream
.pipe( sassGlob() )
.pipe( sass() )
.pipe( postcss( [
cssnano( { reduceIdents: false } ),
autoprefixer( { overrideBrowserslist: [ '> 5%' ] } )
] ) );
if ( settings.basename ) {
stream = stream.pipe( rename( { basename: settings.basename } ) );
}
stream
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( settings.dest ) );
} );
done();
} );
/*
* Run lint.
*/
gulp.task( 'lint', () => {
return gulp.src( [ './src/**/*.js', './tests/**/*.js' ] )
.pipe( eslint( { useEslintrc: true } ) )
.pipe( eslint.format() )
.pipe( eslint.failAfterError() );
} );