forked from globocom/megadraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (77 loc) · 2.32 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
/*
* Copyright (c) 2016, Globo.com (https://github.com/globocom)
*
* License: MIT
*/
const gulp = require("gulp");
const gutil = require("gulp-util");
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
const webpackConfig = require("./webpack.config.js");
// The development server (the recommended option for development)
gulp.task("default", ["dev-server"]);
const host = "localhost";
const port = 8080;
// http://stackoverflow.com/questions/30225866/gulp-webpack-dev-server-callback-before-bundle-is-finished
const hookStream = function(stream, data, cb) {
// Reference default write method
const oldWrite = stream.write;
// Clear hook function
const clearHook = function() {
stream.write = oldWrite;
};
// New stream write with our shiny function
stream.write = function() {
// Old behaviour
oldWrite.apply(stream, arguments);
// Hook
if (arguments[0] === data) {
clearHook();
cb();
}
};
};
gulp.task("sass", function() {
return gulp
.src("./src/styles/**/*.scss")
.pipe(sass.sync({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest("./dist/css"));
});
gulp.task("sass-copy", function() {
return gulp.src("./src/styles/**/*.scss").pipe(gulp.dest("./lib/styles"));
});
gulp.task("site-sass", function() {
return gulp
.src("./website/styles/*.scss")
.pipe(sass.sync().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest("./website/styles/"));
});
gulp.task("site-watch", function() {
gulp.watch("./src/styles/**/*.scss", ["site-sass"]);
gulp.watch("./website/styles/*.scss", ["site-sass"]);
});
gulp.task("dev-server", function(callback) {
gulp.start("site-sass");
gulp.start("site-watch");
// Start a webpack-dev-server
new WebpackDevServer(webpack(webpackConfig), {
stats: {
colors: true
},
contentBase: __dirname + "/website"
}).listen(port, host, function(err) {
hookStream(process.stdout, "webpack: bundle is now VALID.\n", function() {
gutil.log(
"[dev-server]",
gutil.colors.yellow("http://" + host + ":" + port)
);
});
if (err) {
throw new gutil.PluginError("webpack-dev-server", err);
}
});
});