From 90fffad48a3b02518d1c195f378d4cbf8f981b65 Mon Sep 17 00:00:00 2001 From: kendo5731 Date: Sat, 6 Feb 2016 16:10:42 +0100 Subject: [PATCH] chore(): minify css and js files --- .gitignore | 2 ++ README.md | 1 - gulpfile.js | 25 +++++++++++++++++++++---- layouts/partials/footer.html | 2 +- layouts/partials/head.html | 2 +- package.json | 4 ++++ static/js/{theme.js => menu.js} | 0 7 files changed, 29 insertions(+), 7 deletions(-) rename static/js/{theme.js => menu.js} (100%) diff --git a/.gitignore b/.gitignore index c2151e4..27fe8f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ npm-debug.log static/css/theme.css static/css/theme.min.css +static/js/theme.js +static/js/theme.min.js node_modules static/fonts !static/fonts/.gitkeep \ No newline at end of file diff --git a/README.md b/README.md index 97e4b3c..6d37344 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ A theme for [Hugo](https://gohugo.io/), inspired by Atom editor. This repo is a work in progress, there is still work to do, contributions are welcome ! -- Uglify CSS and Javascript - Add integration with Disqus - Add integration with Google Analytics - Add a "Home" link in the top of the menu diff --git a/gulpfile.js b/gulpfile.js index 88bae83..95dfa82 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,24 +1,41 @@ var gulp = require('gulp'); var gutil = require('gulp-util'); var sass = require('gulp-sass'); +var cssnano = require('gulp-cssnano'); +var rename = require('gulp-rename'); +var uglify = require('gulp-uglify'); +var concat = require('gulp-concat'); gulp.task('fonts', function() { gulp.src('./node_modules/bootstrap-sass/assets/fonts/bootstrap/*') .pipe(gulp.dest('./static/fonts')); }); -gulp.task('sass', function() { - return gulp.src("./static/css/theme.scss") +gulp.task('css', function() { + return gulp.src('./static/css/theme.scss') .pipe(sass().on('error', handleError)) + .pipe(gulp.dest('./static/css')) + .pipe(cssnano()) + .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('./static/css')); }); +gulp.task('js', function() { + return gulp.src('./static/js/!(theme.js|theme.min.js)') + .pipe(concat('theme.js')) + .pipe(gulp.dest('./static/js')) + .pipe(uglify()) + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest('./static/js')); +}); + gulp.task('watch', function() { - gulp.watch('./static/**/*.scss', ['sass']); + gulp.watch('./static/**/*.scss', ['css']); + gulp.watch('./static/**/*.js', ['js']); }); gulp.task('default', function() { - gulp.start('fonts', 'sass'); + gulp.start('fonts', 'css', 'js'); }); function handleError(err) { diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 000bb1a..ddba652 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1 +1 @@ - + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 7562a56..eb1357a 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -10,4 +10,4 @@ {{ .Title }} {{ .Hugo.Generator }} - + diff --git a/package.json b/package.json index 28c5066..8850753 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,11 @@ }, "devDependencies": { "gulp": "^3.9.0", + "gulp-concat": "^2.6.0", + "gulp-cssnano": "^2.1.0", + "gulp-rename": "^1.2.2", "gulp-sass": "^2.1.1", + "gulp-uglify": "^1.5.1", "gulp-util": "^3.0.7" }, "scripts": { diff --git a/static/js/theme.js b/static/js/menu.js similarity index 100% rename from static/js/theme.js rename to static/js/menu.js