forked from nachoaIvarez/es6-webapp-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
133 lines (114 loc) · 3.13 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
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
122
123
124
125
126
127
128
129
130
131
132
133
/*eslint-env node */
"use strict";
import gulp from "gulp";
import gulpLoadPlugins from "gulp-load-plugins";
import browserSync from "browser-sync";
import runSequence from "run-sequence";
import del from "del";
const plugins = gulpLoadPlugins();
// SASS
gulp.task("sass", () => {
return gulp.src("src/scss/*.scss")
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.pipe(plugins.sourcemaps.write({includeContent: false}))
.pipe(plugins.sourcemaps.init({loadMaps: true})) // Load sourcemaps generated by sass
.pipe(plugins.autoprefixer({browsers: ["last 2 versions"]}))
.on("error", plugins.util.log)
.pipe(plugins.sourcemaps.write("."))
.pipe(gulp.dest("src/css"))
.pipe(browserSync.stream())
.on("error", plugins.util.log);
});
// CSS
gulp.task("css", () => {
return gulp.src("src/css/*.css")
.pipe(plugins.csso())
.pipe(gulp.dest("dist/css"))
.on("error", plugins.util.log);
});
gulp.task("images", () => {
return gulp.src("src/images/**/*")
.pipe(plugins.cache(plugins.imagemin({
progressive: true,
interlaced: true,
// don"t remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}]
})))
.pipe(gulp.dest("dist/images"));
});
gulp.task("lint", () => {
return gulp.src(["src/js/**/*.js"])
.pipe(plugins.cached("js")) //Process only changed files
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failOnError());
});
// BrowserSync Server
gulp.task("serve", ["sass", "lint"], () => {
browserSync.init([
"src/js/**/*.js",
"src/**/*.html"
], {
notify: false,
server: {
baseDir: ["src"]
},
port: 3000,
browser: [],
tunnel: false
});
gulp.watch("src/scss/**/*.scss", ["sass"]);
gulp.watch("src/js/**/*.js", ["lint"]);
});
// Default
gulp.task("default", ["serve"]);
// Copy files to "dist"
gulp.task("files", () => {
return gulp.src(["src/*.*", "CNAME"], {dot: true}).pipe(gulp.dest("dist"));
});
// Delete dist Directory
gulp.task("clean", del.bind(null, ["dist"]));
gulp.task("jspm", () => {
return gulp.src("src/jspm_packages/**/*").pipe(gulp.dest("dist/jspm_packages"));
});
gulp.task("js", ["lint"], () => {
return gulp.src("src/js/**/*.js").pipe(gulp.dest("dist/js"));
});
// Bundle with jspm
gulp.task("bundle", ["js", "jspm"], plugins.shell.task([
"cd dist; jspm bundle js/main app.js"
]));
gulp.task("html", () => {
var opts = {
conditionals: true
};
return gulp.src("src/**/*.html")
.pipe(plugins.minifyHtml(opts))
.pipe(gulp.dest("dist"));
});
// Uglify the bundle
gulp.task("uglify", () => {
return gulp.src("dist/app.js")
.pipe(plugins.sourcemaps.init({
loadMaps: true
}))
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write("."))
.pipe(gulp.dest("dist"))
.on("error", plugins.util.log);
});
gulp.task("gzip", () => {
return gulp.src("dist/**/*").pipe(plugins.size({title: "build", gzip: true}));
});
gulp.task("build", () => {
runSequence(
"clean",
"files",
"sass",
["css", "images", "html", "bundle"],
"uglify",
"gzip"
)
});