Fix and minify JavaScript

This commit is contained in:
Oliver Davies 2016-01-11 01:44:07 +00:00
parent 18300b2470
commit 8bf421adba
5 changed files with 25 additions and 6 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
/output_*/
/source/assets/css/
/source/assets/fonts/
/source/assets/js/
/.sculpin/
/vendor/
.sass-cache/

View file

@ -32,6 +32,16 @@ app.copy = function(srcFiles, outputDir) {
.pipe(gulp.dest(outputDir));
};
app.addScript = function(paths, filename) {
gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.concat(filename))
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
.pipe(gulp.dest(config.assetsDir + '/js'))
}
gulp.task('fonts', function () {
// Copy fonts from bower_components into source/asset/fonts.
app.copy(config.bowerDir + '/font-awesome/fonts/*', config.assetsDir + '/fonts');
@ -41,7 +51,14 @@ gulp.task('styles', function () {
app.addStyle([
config.bowerDir + '/font-awesome/css/font-awesome.css',
'./sass/styles.scss'
], 'all.css')
], 'all.css');
});
gulp.task('scripts', function () {
app.addScript([
config.bowerDir + '/jquery/dist/jquery.js',
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js'
], 'all.js');
});
gulp.task('images', function () {
@ -59,10 +76,11 @@ gulp.task('watch', function () {
gulp.task('clean', function () {
del.sync(config.assetsDir + '/css');
del.sync(config.assetsDir + '/fonts');
del.sync(config.assetsDir + '/js');
del.sync('./output_*/assets/css/*');
del.sync('./output_*/assets/fonts/*');
});
gulp.task('build', ['clean', 'styles', 'fonts']);
gulp.task('build', ['clean', 'styles', 'scripts', 'fonts']);
gulp.task('default', ['build', 'watch']);

View file

@ -11,6 +11,7 @@
"gulp-plumber": "^1.0.1",
"gulp-sass": "^2.1.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7"
}
}

View file

@ -5,8 +5,8 @@ DEPLOY_USER=deployment
DEPLOY_HOST=www.oliverdavies.uk
DEPLOY_PATH=/var/www/oliverdavies/public
# Rebuild stylesheets.
gulp styles --production
# Rebuild assets.
gulp build --production
./vendor/bin/sculpin generate --env=${ENV} --clean --no-interaction
if [ $? -ne 0 ]; then echo "Could not generate the site"; exit 1; fi

View file

@ -90,8 +90,7 @@
{% include('meetups') %}
</footer>
<script src="{{ site.url }}/components/jquery/jquery.min.js"></script>
<script src="{{ site.url }}/components/bootstrap/js/bootstrap.min.js"></script>
<script src="{{ site.url }}/assets/js/all.js"></script>
{% block scripts %}{% endblock %}