-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
gulpfile.js
121 lines (108 loc) · 3.1 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
"use strict";
var gulp = require("gulp");
var del = require("del");
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var assign = require("object-assign");
var opn = require("opn");
var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const DEV_PORT = process.env.DEV_PORT || 8080;
gulp.task("clean", function() {
return del(["./build/*"]);
});
gulp.task("copy", function() {
gulp.src("./docs/index.html").pipe(gulp.dest("./build"));
gulp.src("./docs/docs.css").pipe(gulp.dest("./build"));
gulp.src("./docs/slick.css").pipe(gulp.dest("./build"));
gulp.src("./docs/slick-theme.css").pipe(gulp.dest("./build"));
gulp.src("./docs/img/**/*").pipe(gulp.dest("./build/img"));
gulp
.src("./node_modules/slick-carousel/slick/fonts/*")
.pipe(gulp.dest("./build/fonts"));
return gulp
.src("./node_modules/slick-carousel/slick/ajax-loader.gif")
.pipe(gulp.dest("./build"));
});
gulp.task(
"watch",
gulp.series(["copy"], function(done) {
gulp.watch(["./docs/index.html"], gulp.parallel(["copy"]));
gulp.watch(["./docs/docs.css"], gulp.parallel(["copy"]));
gulp.watch(["./docs/slick.css"], gulp.parallel(["copy"]));
gulp.watch(["./docs/slick-theme.css"], gulp.parallel(["copy"]));
done();
})
);
gulp.task(
"server",
gulp.series(["watch", "copy"], function() {
console.log("Start");
var myConfig = require("./webpack.config");
if (process.env.SINGLE_DEMO) {
myConfig.entry = {
"docs.js": "./docs/single-demo.js"
};
}
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("dev_docs")
}
})
);
new WebpackDevServer(webpack(myConfig), {
contentBase: "./build",
hot: true,
stats: {
colors: true
}
}).listen(DEV_PORT, "0.0.0.0", function(err, result) {
if (err) {
console.log(err);
} else {
const server_url = `http://0.0.0.0:${DEV_PORT}`;
console.log(`> Dev Server started at ${server_url}`);
opn(server_url);
}
});
})
);
// gulp tasks for building dist files
gulp.task("dist-clean", function() {
return del(["./dist/*"]);
});
var distConfig = require("./webpack.config.dist.js");
gulp.task("dist-unmin", function(cb) {
var unminConfig = assign({}, distConfig);
unminConfig.output.filename = "react-slick.js";
unminConfig.mode = "none";
return webpack(unminConfig, function(err, stat) {
console.error(err);
cb();
});
});
gulp.task("dist-min", function(cb) {
var minConfig = assign({}, distConfig);
minConfig.output.filename = "react-slick.min.js";
minConfig.plugins = minConfig.plugins.concat(
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: {
warnings: false
}
})
);
return webpack(minConfig, function(err, stat) {
console.error(err);
cb();
});
});
gulp.task(
"dist",
gulp.series(["dist-clean", "dist-unmin", "dist-min"], function(done) {
done();
})
);
gulp.task("default", gulp.series(["watch", "server"]));