-
Notifications
You must be signed in to change notification settings - Fork 170
/
gulpfile.js
81 lines (72 loc) · 2.05 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
var package = require('./package.json');
var gulp = require("gulp");
var gutil = require("gulp-util");
var babel = require("gulp-babel");
var babelify = require("babelify");
var browserify = require("browserify");
var sourcemaps = require("gulp-sourcemaps");
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var header = require("gulp-header");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var less = require("gulp-less");
const BANNER = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @date <%= new Date() %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
const BROWSERIFY_OPTIONS = {
debug: true
};
const UGLIFY_OPTIONS = {
preserveComments: 'some'
};
const LESS_OPTIONS = {};
// JS Compilation
gulp.task("build", function() {
// Bundle using Browserify + Babel transform
return browserify(BROWSERIFY_OPTIONS)
.transform(babelify)
.require('src/index.js', { entry: true})
.bundle()
.on("error", function (err) {
console.log("Error : " + err.message);
})
// Compiled file + sourcemaps
.pipe(source('jquery.resizableColumns.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write())
.pipe(header(BANNER, { pkg: package }))
.pipe(gulp.dest('dist/'))
// Minified file + sourcemaps
.pipe(uglify(UGLIFY_OPTIONS))
.pipe(rename(function(path) {
path.extname = '.min' + path.extname;
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
});
// LESS compilation
gulp.task("less", function() {
return gulp.src("less/index.less")
.pipe(less(LESS_OPTIONS))
.pipe(rename(function(path) {
path.basename = 'jquery.resizableColumns';
}))
.pipe(gulp.dest("dist"));
});
// Watch tasks
gulp.task('build:watch', function() {
gulp.watch('src/**/*.js', ['build']);
});
gulp.task('less:watch', function() {
gulp.watch('less/**/*.less', ['less']);
});
// Aliases
gulp.task('watch', ['build:watch', 'less:watch']);
gulp.task('default', ['build', 'less']);