diff --git a/.gitignore b/.gitignore index de4d1f0..e3fbd98 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -dist +build node_modules diff --git a/gulpfile.js b/gulpfile.js index fab3ded..bfc4b4a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,17 +1,26 @@ -const gulp = require('gulp'); -const sass = require('gulp-sass'); -const concat = require('gulp-concat'); -const gutil = require('gulp-util'); +const gulp = require('gulp') +const sass = require('gulp-sass') +const concat = require('gulp-concat') +const gutil = require('gulp-util') +const imagemin = require('gulp-imagemin') +const cache = require('gulp-cache') +const gulpIf = require('gulp-if') +const browserify = require('browserify') +const del = require('del') -var budo = require('budo') -var babelify = require('babelify') +const source = require('vinyl-source-stream') +const buffer = require('vinyl-buffer') +const sourcemaps = require('gulp-sourcemaps') -const cssFiles = 'public/scss/**/*.?(s)css'; +const budo = require('budo') +const babelify = require('babelify') + +const cssFiles = 'public/scss/**/*.?(s)css' let css = gulp.src(cssFiles) .pipe(sass()) .pipe(concat('style.css')) - .pipe(gulp.dest('assets')); + .pipe(gulp.dest('build')) gulp.task('watch', function(cb) { budo("app.js", { @@ -20,12 +29,59 @@ gulp.task('watch', function(cb) { browserify: { transform: babelify } - }).on('exit', cb); - gulp.watch(cssFiles, function() { - console.log("Compiling CSS") - return gulp.src(cssFiles) - .pipe(sass()) - .pipe(concat('style.css')) - .pipe(gulp.dest('./dist')) - }); -}); + }).on('exit', cb) + gulp.watch(cssFiles, gulp.series(["sass"])) +}) + +gulp.task("clean", function(done) { + del.sync('build') + done() +}) + +gulp.task("sass", function() { + return gulp.src(cssFiles) + .pipe(sass()) + .pipe(concat('style.css')) + .pipe(gulp.dest('./build')) +}) + +gulp.task("assets", function() { + return gulp.src(["public/**/*", "!public/scss", "!public/scss/**/*"]) + .pipe(gulpIf('*.+(png|jpg|jpeg|gif|svg)', + cache(imagemin({ + interlaced: true + })) + )) + .pipe(gulp.dest('build')) +}) + +gulp.task('js', function() { + return gulp.src(['app.js', "components/**/*"]) + .pipe(babel({ + presets: [ + ['@babel/env', { + modules: false + }] + ] + })) + .pipe(gulp.dest('build')) +}) + +gulp.task('js', function() { + let b = browserify({ + entries: 'app.js', + debug: false, + transform: [babelify.configure({ + presets: ['@babel/preset-env', '@babel/preset-react'] + })] + }) + return b.bundle() + .pipe(source('app.js')) + .pipe(buffer()) + .pipe(sourcemaps.init({ loadMaps: true })) + .pipe(gulp.dest('build')) +}) + +gulp.task('build', gulp.parallel(['clean', 'assets', 'js', 'sass', function(done) { + done() +}])) diff --git a/index.html b/index.html deleted file mode 100644 index f174319..0000000 --- a/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - -
- - - -