-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
67 lines (60 loc) · 1.98 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
const gulp = require( 'gulp' );
const babel = require('gulp-babel');
const eslint = require( 'gulp-eslint' );
const terser = require( 'gulp-terser' );
const rename = require( 'gulp-rename' );
const { sass } = require("@mr-hope/gulp-sass");
const minifyCSS = require( 'gulp-clean-css' );
const autoprefixer = require( 'gulp-autoprefixer' );
const sourcemaps = require( 'gulp-sourcemaps' );
gulp.task('compile:js', () => {
return gulp.src( 'src/js/**/*.js' )
.pipe( sourcemaps.init( { largeFile: true } ) )
.pipe( eslint() )
.pipe( eslint.format() )
.pipe( babel() )
.pipe( sourcemaps.write( '/.' ) )
.pipe( gulp.dest( 'dist/js' ) );
} );
gulp.task('minify:js', () => {
return gulp.src( [
'dist/js/**/*.js',
'!dist/js/**/*.min.js',
] )
// .pipe( sourcemaps.init( { largeFile: true } ) )
.pipe( terser( { format: { comments: false } } ) )
.pipe( rename( { suffix: '.min' } ) )
// .pipe( sourcemaps.write( '/.' ) )
.pipe( gulp.dest( 'dist/js' ) );
} );
gulp.task('compile:scss', () => {
return gulp.src( 'src/scss/**/*.scss' )
.pipe( sourcemaps.init( { largeFile: true } ) )
.pipe( sass().on( 'error', sass.logError ) )
.pipe( autoprefixer() )
.pipe( sourcemaps.write( '/.' ) )
.pipe( gulp.dest( 'dist/css' ) );
});
gulp.task( 'minify:css', function () {
return gulp.src( [
'dist/css/**/*.css',
'!dist/css/**/*.min.css'
] )
// .pipe( sourcemaps.init() )
.pipe( minifyCSS() )
.pipe( rename( { suffix: '.min' } ) )
// .pipe( sourcemaps.write( '/.' ) )
.pipe( gulp.dest( 'dist/css' ) );
} );
gulp.task( 'buildJs', gulp.series( 'compile:js', 'minify:js' ) );
gulp.task( 'buildCss', gulp.series( 'compile:scss', 'minify:css' ) );
gulp.task( 'build', gulp.series( 'buildJs', 'buildCss' ) );
gulp.task( 'watch', () => new Promise( ( resolve, reject ) => {
try {
gulp.watch( 'src/js/**/*.js', {ignoreInitial: true}, gulp.series('buildJs') );
gulp.watch( 'src/scss/**/*.scss', {ignoreInitial: true}, gulp.series('buildCss') );
resolve();
} catch ( e ) {
reject( e );
}
} ) );