-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
85 lines (74 loc) · 2.2 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
var browserify = require('gulp-browserify'),
concat = require('gulp-concat'),
connect = require('gulp-connect'),
gulp = require('gulp'),
open = require('gulp-open'),
plumber = require('gulp-plumber'),
livereload = require('gulp-livereload'),
minifycss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
del = require('del');
gulp
// performs magic
.task('browserify', function(){
gulp.src('src/js/main.js')
.pipe(plumber())
.pipe(
browserify({
transform: 'reactify',
debug: !gulp.env.production
})
)
.pipe(concat('main.js'))
.pipe(rename({suffix: '.min'})) //rename压缩后的文件名
.pipe(uglify())
.pipe(plumber.stop())
.pipe(gulp.dest('dist/js'))
.pipe(livereload());
})
.task('minifycss', function() {
return gulp.src('src/assets/**/*.css') //压缩的文件
.pipe(minifycss()) //执行压缩
.pipe(concat('main.css'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/assets/')) //输出文件夹
.pipe(livereload());
})
// moves source files to dist
.task('copy', function(){
gulp
.src('src/index.html')
.pipe(gulp.dest('dist'));
gulp
.src('src/assets/**/*.*')
.pipe(gulp.dest('dist/assets'));
gulp
.src('src/img/**/*.*')
.pipe(gulp.dest('dist/img'));
})
// local development server
.task('connect', function(){
connect.server({
root: ['dist'],
port: '8080',
base: 'http://localhost',
livereload: true
});
})
// opens the application in chrome
.task('open', function(){
gulp
.src('dist/index.html')
.pipe(
open('', {app: 'google chrome',url: 'http://localhost:8080/'})
);
})
// build the application
.task('default', ['browserify','copy', 'connect', 'open'])
.task('default2', ['browserify', 'copy'])
// watch for source changes
.task('watch', ['default'], function(){
livereload.listen();
gulp.watch('src/**/*.*', ['default2']);
});