-
Notifications
You must be signed in to change notification settings - Fork 219
/
gulpfile.js
95 lines (82 loc) · 2.43 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
/*
* Copyright (c) 2016, Globo.com (https://github.com/globocom)
*
* License: MIT
*/
const gulp = require("gulp");
const gutil = require("gulp-util");
const gulpSass = require("gulp-sass")(require("sass"));
const autoprefixer = require("gulp-autoprefixer");
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
const webpackConfig = require("./webpack.config.js");
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();
}
};
};
function sass() {
return gulp
.src("./src/styles/megadraft.scss")
.pipe(
gulpSass.sync({ outputStyle: "expanded" }).on("error", gulpSass.logError)
)
.pipe(autoprefixer())
.pipe(gulp.dest("./dist/css"));
}
function sassCopy() {
return gulp.src("./src/styles/**/*.scss").pipe(gulp.dest("./lib/styles"));
}
function siteSass(done) {
return gulp
.src("./website/styles/*.scss")
.pipe(gulpSass.sync().on("error", gulpSass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest("./website/styles/"));
}
function siteWatch() {
gulp.watch("./src/styles/**/*.scss", siteSass);
gulp.watch("./website/styles/*.scss", siteSass);
}
const devServer = gulp.parallel([siteSass, siteWatch], function devServer() {
// 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);
}
});
});
exports.sass = sass;
exports["sass-copy"] = sassCopy;
exports["site-sass"] = siteSass;
exports["site-watch"] = siteWatch;
exports["dev-server"] = devServer;
// The development server (the recommended option for development)
exports.default = devServer;