-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·80 lines (74 loc) · 2.04 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
var gulp = require('gulp'),
browserSync = require('browser-sync'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
mochaPhantomJS = require('gulp-mocha-phantomjs'),
uglify = require('gulp-uglifyjs');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var config = require('./webpack.config');
gulp.task('browser-sync', function () {
'use strict';
browserSync({
server: {
//serve tests and the root as base dirs
baseDir: ['./test/', './'],
//make tests.html the index file
index: 'tests.html'
}
});
});
gulp.task('browserify', function() {
return browserify('./test/index.js')
.transform('babelify', {
presets: ['stage-0'],
plugins: ['transform-runtime']
})
.bundle()
.on('error', function (err) {
console.log(err.toString());
this.emit('end');
})
.pipe(source('tests-browserify.js'))
.pipe(gulp.dest('tmp/'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('dist', function() {
return gulp.src('./src/index.js')
.pipe(webpackStream(config))
.pipe(gulp.dest('./dist/'));
});
gulp.task('test', function () {
return gulp.src('./test/tests.html')
.pipe(mochaPhantomJS({reporter: 'spec', dump:'./tmp/test.log'}));
});
gulp.task('serve', ['browserify', 'browser-sync'], function () {
'use strict';
//when tests.js changes, browserify code and execute tests
gulp.watch(['test/tests.js', 'src/text-changer.js'], ['browserify', 'test']);
});
gulp.task('uglify', function() {
gulp.src('./dist/index.js')
.pipe(uglify('v.min.js', {
compress: {
warnings: false,
drop_console: false,
dead_code: true,
unused: true,
booleans: true,
join_vars: true,
negate_iife: true,
sequences: true,
properties: true,
evaluate: true,
loops: true,
if_return: true,
cascade: true,
unsafe: true
},
output: {
comments: false
}
}))
.pipe(gulp.dest('./'));
});