You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.6 KiB
JavaScript
112 lines
2.6 KiB
JavaScript
7 years ago
|
'use strict';
|
||
|
|
||
|
const gulp = require("gulp");
|
||
|
const path = require("path");
|
||
|
const presetES2015 = require("@joepie91/gulp-preset-es2015");
|
||
|
const presetJade = require("@joepie91/gulp-preset-jade");
|
||
|
const presetSCSS = require("@joepie91/gulp-preset-scss");
|
||
|
const webpackStream = require("webpack-stream");
|
||
|
const webpack = require("webpack");
|
||
|
const rename = require("gulp-rename");
|
||
|
const nodemon = require("gulp-nodemon");
|
||
|
const livereload = require("gulp-livereload");
|
||
|
const net = require("net");
|
||
|
|
||
|
var nodemonRestarting = false;
|
||
|
|
||
|
function tryReload() {
|
||
|
if (nodemonRestarting === false) {
|
||
|
livereload.changed(arguments[0].path);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* The following resolves JacksonGariety/gulp-nodemon#33 */
|
||
|
process.once("SIGINT", function() {
|
||
|
process.exit(0);
|
||
|
});
|
||
|
|
||
|
gulp.task("jade", function() {
|
||
|
return gulp.src("./src/**/*.jade")
|
||
|
.pipe(presetJade({
|
||
|
basePath: __dirname
|
||
|
}))
|
||
|
.pipe(gulp.dest("./dist"));
|
||
|
});
|
||
|
|
||
|
gulp.task("scss", function() {
|
||
|
return gulp.src("./src/**/*.scss")
|
||
|
.pipe(presetSCSS({
|
||
|
basePath: __dirname
|
||
|
}))
|
||
|
.pipe(gulp.dest("./dist"));
|
||
|
});
|
||
|
|
||
|
gulp.task('webpack', function(){
|
||
|
return gulp.src("./src/index.js")
|
||
|
.pipe(webpackStream({
|
||
|
watch: true,
|
||
|
module: {
|
||
|
preLoaders: [{
|
||
|
test: /\.tag$/,
|
||
|
loader: "riotjs-loader",
|
||
|
exclude: /node_modules/,
|
||
|
query: {
|
||
|
type: "babel",
|
||
|
template: "jade"
|
||
|
}
|
||
|
}],
|
||
|
loaders: [
|
||
|
{ test: /\.js$/, loader: "babel-loader" },
|
||
|
{ test: /\.json$/, loader: "json-loader" }
|
||
|
]
|
||
|
},
|
||
|
plugins: [ new webpack.ProvidePlugin({riot: "riot"}) ],
|
||
|
resolveLoader: { root: path.join(__dirname, "node_modules") },
|
||
|
resolve: {
|
||
|
extensions: [
|
||
|
"",
|
||
|
".tag",
|
||
|
".web.js", ".js",
|
||
|
".web.json", ".json"
|
||
|
]
|
||
|
},
|
||
|
debug: false
|
||
|
}))
|
||
|
.pipe(rename("bundle.js"))
|
||
|
.pipe(gulp.dest("./dist"));
|
||
|
});
|
||
|
|
||
|
function checkServerUp(){
|
||
|
setTimeout(function(){
|
||
|
var sock = new net.Socket();
|
||
|
sock.setTimeout(50);
|
||
|
sock.on("connect", function(){
|
||
|
nodemonRestarting = false;
|
||
|
console.log("Triggering page reload...");
|
||
|
tryReload("*");
|
||
|
sock.destroy();
|
||
|
})
|
||
|
.on("timeout", checkServerUp)
|
||
|
.on("error", checkServerUp)
|
||
|
.connect(4000);
|
||
|
}, 70);
|
||
|
}
|
||
|
|
||
|
gulp.task("nodemon", ["jade", "scss"], function() {
|
||
|
nodemon({
|
||
|
script: "./local-server.js",
|
||
|
delay: 500,
|
||
|
ignore: ["dist/*"]
|
||
|
}).on("restart", function() {
|
||
|
nodemonRestarting = true;
|
||
|
}).on("start", checkServerUp);
|
||
|
})
|
||
|
|
||
|
gulp.task('watch', ["nodemon"], function () {
|
||
|
livereload.listen();
|
||
|
gulp.watch("./src/**/*.scss", ["scss"]);
|
||
|
gulp.watch("./src/**/*.jade", ["jade"]);
|
||
|
gulp.watch(['./dist/**/*']).on('change', tryReload);
|
||
|
});
|
||
|
|
||
|
gulp.task("default", ["watch", "webpack"]);
|