-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (84 loc) · 2.26 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
'use strict';
const del = require('del'),
gulp = require('gulp'),
cleanCSS = require('gulp-clean-css'),
less = require('gulp-less'),
named = require('vinyl-named'),
webpack = require('webpack'),
webpackStream = require('webpack-stream');
const JS_SRC = 'static/js/src/';
const JS_DIST = 'static/js/dist/';
const CSS_SRC = 'static/css/src/';
const CSS_DIST = 'static/css/dist/';
// Cleans up the dist folders.
gulp.task('clean', () => del([CSS_DIST, JS_DIST]));
// Copies library files.
gulp.task('libs', () => {
return gulp.src(JS_SRC + 'libs/*.js')
.pipe(gulp.dest(JS_DIST + 'libs/'));
});
gulp.task('css-dev', () => {
return gulp.src(CSS_SRC + '*.less', { sourcemaps: true })
.pipe(less())
.pipe(gulp.dest(CSS_DIST));
});
gulp.task('css-dist', () => {
return gulp.src(CSS_SRC + '*.less', { sourcemaps: true })
.pipe(less())
.pipe(cleanCSS())
.pipe(gulp.dest(CSS_DIST));
});
const webpackConfig = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
[
'env',
{
targets: {
browsers: ["ie >= 11"]
},
modules: false
}
]
]
}
}
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})
]
};
gulp.task('js', () => {
return gulp.src(JS_SRC + '*.js')
.pipe(named())
.pipe(webpackStream(webpackConfig, webpack))
.on('error', function(err) {
console.error(err);
this.emit('end');
})
.pipe(gulp.dest(JS_DIST));
});
gulp.task('dev', gulp.series('clean', gulp.parallel('libs', 'css-dev', 'js')));
gulp.task('dist', gulp.series('clean', gulp.parallel('libs', 'css-dist', 'js')));
gulp.task('default', gulp.series('dist'))
gulp.task('watch', () => {
// Watch css and libs
gulp.watch(CSS_SRC + '*.less', gulp.series('css-dev'));
gulp.watch(CSS_SRC + 'libs/*.css', gulp.series('libs'));
// Watch js and libs
gulp.watch(JS_SRC + '*.js', gulp.series('js'));
gulp.watch(JS_SRC + 'libs/*.js', gulp.series('libs'));
});