-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.babel.js
70 lines (57 loc) · 1.7 KB
/
gulpfile.babel.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
import { readdirSync } from "fs";
import gulp from "gulp";
import uglify from "gulp-uglify";
import rollup from "rollup-stream";
import babel from "rollup-plugin-babel";
import source from "vinyl-source-stream";
import buffer from "vinyl-buffer";
import less from "gulp-less";
import cssnano from "gulp-cssnano";
import eslint from "gulp-eslint";
import { camelize } from "./src/utils";
gulp.task("js", () => {
buildJsEntry("./src/core.js", "highlight-share", "HighlightShare", "dist/");
});
gulp.task("sharers", () => {
readdirSync("./src/sharers").forEach((file) => {
const name = file.replace(/\.js$/i, "");
if (name === file) return;
buildJsEntry(`./src/sharers/${file}`, name, `HighlightShareVia${camelize(name)}`, "dist/sharers/");
});
});
gulp.task("less", () => {
gulp.src("./style/less/highlight-share.less")
.pipe(less())
.pipe(cssnano({ autoprefixer: false }))
.pipe(gulp.dest("dist/"))
;
});
gulp.task("lint", () => {
const result = gulp
.src([ "./src/**/*.js", "./test/**/**.js", "./gulpfile.babel.js" ])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
return result;
});
gulp.task("default", [ "lint" ], () => {
gulp.start("js");
gulp.start("sharers");
gulp.start("less");
});
function buildJsEntry(file, name, standalone, output) {
rollup({
input: file,
format: "umd",
name: standalone,
plugins: [ babel({
babelrc: false,
presets: [ [ "es2015", { modules: false }] ]
}) ]
})
.pipe(source(`${name}.js`))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(output))
;
}