forked from Rainno/vue-es6-webPack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
122 lines (112 loc) · 3.06 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
var webpackConfig = require('./webpack.config.js');
// 引入 gulp
var gulp = require('gulp');
var webpack = require("webpack");
// 引入组件
var plugins = require('gulp-load-plugins')();//加载其他插件
require('gulp-connect');
//配置
jshint_config = {
eqeqeq: false,
forin: false,
debug: true,
asi: false,
strict: false
};
autoprefixer_config = {
browsers: [
'last 2 versions',
'safari 5',
'ie 8',
'ie 9',
'ie 6-7',
'opera <= 12',
'ios <= 8',
'android <= 4',
'Firefox <= 20'
],
cascade: true,
remove: false
};
// 编译Sass
gulp.task('sass', function () {
gulp.src('./styles/**/*.scss')
.pipe(plugins.plumber())
.pipe(plugins.sass())
.pipe(plugins.autoprefixer(autoprefixer_config))
.pipe(gulp.dest('./projects/'))
.pipe(plugins.connect.reload());
});
// 检查脚本
gulp.task('lint', function () {
gulp.src('./scripts/!(vendor)/*.js')
.pipe(plugins.jshint(jshint_config))
.pipe(plugins.jshint.reporter('default'));
//.pipe(plugins.connect.reload());
});
//babel
gulp.task('babel', function () {
gulp.src('./es6/**/*.js')
.pipe(plugins.plumber())
.pipe(plugins.babel({
presets: ['es2015']
}))
.pipe(gulp.dest('./projects/'));
// .pipe(plugins.connect.reload());
});
// 合并,压缩文件
gulp.task('scripts', function () {
gulp.src('./scripts/*.js')
.pipe(plugins.concat('all.js'))
.pipe(gulp.dest('./dist'))
.pipe(plugins.rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist'))
});
gulp.task('webserver', function () {
plugins.connect.server({
livereload: true,
port: 8088
//host: '10.0.15.103'
// host: '192.168.0.101'
});
});
gulp.task('html', function () {
gulp.src('./projects/**/*.html')
.pipe(plugins.connect.reload());
});
gulp.task('js', function () {
gulp.src('./projects/**/*.js')
.pipe(plugins.connect.reload());
});
gulp.task('css', function () {
gulp.src('./projects/**/*.css')
.pipe(plugins.connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['./projects/**/*.html'], ['html']);
gulp.watch(['./*.html'], ['html']);
gulp.watch('./styles/**/*.scss', ['sass']);
gulp.watch('./es6/**/*.js', ['babel']);
plugins.watch('./projects/**/*.js')
.pipe(plugins.connect.reload());
// plugins.watch('./projects/**/*.css')
// .pipe(plugins.connect.reload());
// gulp.watch('./projects/**/*.css', ['css']);
// plugins.watch('./scripts/**/*.js')
// .pipe(plugins.connect.reload());
});
// 默认任务
gulp.task('default', function () {
gulp.run('sass', 'watch', 'webserver', 'babel');
});
/*
gulp.task("webpack", function(callback) {
var myConfig = Object.create(webpackConfig);
webpack(myConfig, function(err, stats) {
callback();
});
});
gulp.task('watchVue',function(){
gulp.watch(['resource/js/!**!/!*.vue','resource/js/!**!/!*.js'], ['webpack']);
});*/