-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
80 lines (72 loc) · 1.84 KB
/
gulpfile.js
File metadata and controls
80 lines (72 loc) · 1.84 KB
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
var gulp = require("gulp"),
browserSync = require("browser-sync"),
less = require("gulp-less"),
nodemon = require("gulp-nodemon"),
webpack = require("webpack"),
webpackConfig = require("./webpack.config.js"),
webpackDevMiddleware = require("webpack-dev-middleware"),
webpackHotMiddleware = require("webpack-hot-middleware"),
bundler = webpack(webpackConfig);
const autoprefixer = require("gulp-autoprefixer");
const cleanCSS = require("gulp-clean-css");
// Main Entry
gulp.task("serve", ["nodemon", "less"], function () {
browserSync.init({
proxy: {
target: "localhost:3000",
ws: true
},
port: 8080,
notify: true,
middleware: [
webpackDevMiddleware(bundler, {
publicPath: webpackConfig.output.publicPath,
stats: { colors: true }
}),
webpackHotMiddleware(bundler)
]
});
gulp.watch("frontend/styles/**/*.less", ["less"]);
gulp.watch("backend/views/**/*.pug").on("change", browserSync.reload);
});
// less to CSS and Inject via BrowserSync
gulp.task("less", function () {
return gulp
.src("./frontend/styles/**/*.less")
.pipe(less({ outputStyle: "compressed" }))
.on("error", swallowError)
.pipe(
autoprefixer({
browsers: ["last 2 versions"],
cascade: false
})
)
.pipe(cleanCSS())
.pipe(gulp.dest("./public/css/"))
.pipe(browserSync.stream());
});
//Nodemon
gulp.task("nodemon", function (cb) {
var started = false;
return nodemon({
script: "app.js",
nodeArgs: ["--inspect"],
ignore: ["frontend/", "gulpfile.js", "webpack.config.js", "public/"]
})
.on("start", function () {
if (!started) {
cb();
started = true;
}
})
.once("quit", function () {
process.exit();
});
});
gulp.task("default", ["serve"]);
gulp.task("build", ["less"]);
function swallowError(error) {
// If you want details of the error in the console
console.log(error.toString());
this.emit("end");
}