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.

117 lines
2.8 KiB
JavaScript

const Promise = require("bluebird");
const path = require("path");
const gulp = require("gulp");
const webpackStream = require("webpack-stream");
const webpack = require("webpack");
const gulpNamedLog = require("gulp-named-log");
const gulpRename = require("gulp-rename");
const gulpNodemon = require("gulp-nodemon");
const gulpCached = require("gulp-cached");
const presetSCSS = require("@joepie91/gulp-preset-scss");
const awaitServer = require("await-server");
const gulpLivereload = require("gulp-livereload");
const patchLivereloadLogger = require("@joepie91/gulp-partial-patch-livereload-logger");
patchLivereloadLogger(gulpLivereload);
let config = {
scss: {
source: "./src/scss/**/*.scss",
destination: "./public/css/"
},
cssModules: []
}
let serverLogger = gulpNamedLog("server");
gulp.task("nodemon", ["scss", "livereload"], () => {
gulpNodemon({
script: "server.js",
ignore: [
"gulpfile.js",
"node_modules",
"public"
],
ext: "js pug"
}).on("start", () => {
Promise.try(() => {
serverLogger.info("Starting...");
return awaitServer(3000);
}).then(() => {
serverLogger.info("Started!");
gulpLivereload.changed("*");
});
});
});
gulp.task("scss", () => {
return gulp.src(config.scss.source)
.pipe(presetSCSS({
livereload: gulpLivereload
}))
.pipe(gulp.dest(config.scss.destination));
});
gulp.task("livereload", () => {
gulpLivereload.listen({
quiet: true
});
});
gulp.task("webpack-watch", ["livereload"], () => {
return gulp.src("./src/frontend/index.js")
.pipe(webpackStream({
watch: true,
module: {
preLoaders: [{
test: /\.tag$/,
loader: "riotjs-loader",
exclude: /node_modules/,
query: {
type: "es6",
template: "pug",
parserOptions: {
js: {
presets: ["es2015-riot"]
}
}
}
}],
loaders: [{
test: /\.js/,
loader: "babel-loader",
query: {
presets: ["es2015"]
}
}, {
test: /\.json$/,
loader: "json-loader"
}]
},
resolve: {
extensions: [
"",
".tag",
".web.js", ".js",
".web.json", ".json"
]
},
plugins: [ new webpack.ProvidePlugin({riot: "riot"}) ],
debug: true
}))
.pipe(gulpRename("bundle.js"))
.pipe(gulpNamedLog("webpack").stream())
.pipe(gulpLivereload())
.pipe(gulp.dest("./public/js/"));
});
gulp.task("watch-css", () => {
gulp.watch(config.scss.source, ["scss"]);
});
gulp.task("watch", ["webpack-watch", "nodemon", "watch-css"]);
gulp.task("default", ["watch"]);