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.
110 lines
2.8 KiB
JavaScript
110 lines
2.8 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-fixed");
|
|
var webpackLib = require("webpack")
|
|
|
|
const presetSCSS = require("@joepie91/gulp-preset-scss");
|
|
|
|
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('webpack', function(){
|
|
return gulp.src("./lib/frontend/index.js")
|
|
.pipe(webpack({
|
|
watch: true,
|
|
module: {
|
|
preLoaders: [{
|
|
test: /\.tag$/,
|
|
loader: "riotjs-loader",
|
|
exclude: /node_modules/,
|
|
query: {
|
|
type: "es6",
|
|
template: "pug",
|
|
/* NOTE: `node-sass` is implicitly required based on the
|
|
`type` attribute in the components */
|
|
parserOptions: {
|
|
js: {
|
|
presets: ["es2015-riot"]
|
|
}
|
|
}
|
|
}
|
|
}],
|
|
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"));
|
|
});
|
|
|
|
gulp.task("scss", () => {
|
|
return gulp.src("./scss/**/*")
|
|
.pipe(presetSCSS({
|
|
livereload: livereload
|
|
}))
|
|
.pipe(gulp.dest("./public/stylesheets/"));
|
|
});
|
|
|
|
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", 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/**/*.pug', '!views/client/**/*.pug', '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"]);
|