-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
57 lines (50 loc) · 1.54 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
'use strict';
const gulp = require('gulp');
const { series, parallel } = require('gulp');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass')(require('sass'));
const cleanCss = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const plumber = require('gulp-plumber');
const browserSync = require('browser-sync').create();
// browser sync
function browserSyncTask() {
browserSync.init({
proxy: 'http://localhost/regexp',
port: 3000,
});
}
// sassコンパイル
function sassTask() {
return gulp.src('./app/css/*.scss')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(rename({extname: '.min.css'}))
.pipe(cleanCss({advanced:false}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./app/css'))
.pipe(browserSync.stream());
}
// js minify
function jsMinifyTask() {
return gulp.src(['./app/js/*.js', '!./app/js/*.min.js'])
.pipe(plumber())
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('./app/js/'))
.pipe(browserSync.stream());
}
// ファイル監視
function watchTask() {
gulp.watch('./app/css/*.scss', sassTask);
gulp.watch(['./app/js/*.js', '!./app/js/*.min.js'], jsMinifyTask);
}
// デフォルト処理
const defaultTask = series(parallel(browserSyncTask, watchTask), () => {
browserSync.reload();
});
exports.sass = sassTask;
exports.jsminify = jsMinifyTask;
exports.default = defaultTask;