This repository has been archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (57 loc) · 1.92 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
var gulp = require('gulp'),
less = require('gulp-less'),
browserSync = require('browser-sync').create(),
cleanCSS = require('gulp-clean-css'),
LessPluginAutoPrefix = require('less-plugin-autoprefix'),
rename = require("gulp-rename"),
sourcemaps = require('gulp-sourcemaps');
var autoprefix = new LessPluginAutoPrefix({
browsers: ["last 10 versions"]
});
var browser_config = {
baseDir: 'dist',
watchFiles: ['dist/*.html', 'dist/css/*.css', 'dist/js/*.js', 'dist/js/app/*.js']
};
gulp.task('compileLess', function () { //改个名字啦
gulp.src('src/less/style.less')
.pipe(sourcemaps.init())
.pipe(less({
plugins: [autoprefix]
}))
.pipe(sourcemaps.write(''))
.pipe(gulp.dest('dist/css'));
//.pipe(gulp.dest('web/Public/css'));不需要完整css只要mini版
});
gulp.task('minify-css', function () {
return gulp.src('dist/css/style.css')
.pipe(cleanCSS({
advanced: false,
compatibility: 'ie8',
output: 'style-min',
keepSpecialComments: '*',
keepBreaks: false
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist/css'))
.pipe(gulp.dest('web/Public/css'));
});
gulp.task('copyJS', function () {
return gulp.src('dist/js/*.js')
.pipe(gulp.dest('web/Public/js'))
});
gulp.task('browser-sync', ['compileLess', 'minify-css'], function () {
browserSync.init({
files: browser_config.watchFiles,
server: {
baseDir: browser_config.baseDir
}
});
gulp.watch('src/less/*.less', ['compileLess']);
gulp.watch('dist/css/*.css', ['minify-css']);
//gulp.watch('dist/js/*.js', ['copyJS']);
gulp.watch("dist/*.html").on('change', browserSync.reload);
});
gulp.task('update_css', ['compileLess', 'minify-css']);
gulp.task('default', ['compileLess', 'minify-css', 'browser-sync']);