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.
102 lines
2.5 KiB
JavaScript
102 lines
2.5 KiB
JavaScript
var gulp = require('gulp');
|
|
|
|
var path = require('path');
|
|
var rename = require('gulp-rename');
|
|
var livereload = require('gulp-livereload');
|
|
var nodemon = require("gulp-nodemon");
|
|
var net = require("net");
|
|
var webpack = require("webpack-stream");
|
|
var webpackLib = require("webpack")
|
|
|
|
var presetES2015 = require("@joepie91/gulp-preset-es2015");4
|
|
|
|
var nodemonRestarting = false;
|
|
|
|
function tryReload() {
|
|
if (nodemonRestarting === false) {
|
|
livereload.changed.apply(null, arguments);
|
|
}
|
|
}
|
|
|
|
/* The following resolves JacksonGariety/gulp-nodemon#33 */
|
|
process.once("SIGINT", function() {
|
|
process.exit(0);
|
|
});
|
|
|
|
gulp.task("babel", function() {
|
|
return gulp.src("./src/**/*.js")
|
|
.pipe(presetES2015({
|
|
basePath: __dirname
|
|
}))
|
|
.pipe(gulp.dest("./lib"));
|
|
})
|
|
|
|
gulp.task('webpack', function(){
|
|
return gulp.src("./src/frontend/index.js")
|
|
.pipe(webpack({
|
|
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" },
|
|
//{ loader: "logging-loader" }
|
|
]
|
|
},
|
|
plugins: [ new webpackLib.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("./public/js"));
|
|
});
|
|
|
|
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(3000);
|
|
}, 70);
|
|
}
|
|
|
|
gulp.task("nodemon", ["babel"], function() {
|
|
nodemon({
|
|
script: "./app.js",
|
|
delay: 500,
|
|
ignore: ["public"]
|
|
}).on("restart", function() {
|
|
nodemonRestarting = true;
|
|
}).on("start", checkServerUp);
|
|
})
|
|
|
|
gulp.task('watch', ["nodemon"], function () {
|
|
livereload.listen();
|
|
gulp.watch(['./**/*.css', 'views/**/*.jade', '!views/client/**/*.jade', 'package.json', "./public/js/**/*.js"]).on('change', tryReload);
|
|
gulp.watch(['public/views/**/*.html', 'public/elements/**/*']).on('change', function() { tryReload("*"); }); // We need to explicitly reload everything here; Polymer doesn't do partial reloading
|
|
});
|
|
|
|
gulp.task("default", ["watch", "webpack"]); |