Skip to content

Instantly share code, notes, and snippets.

@bidwall
Created March 14, 2017 20:21
Show Gist options
  • Save bidwall/b04afbecf42c9f00a10d5c700e65ecb0 to your computer and use it in GitHub Desktop.
Save bidwall/b04afbecf42c9f00a10d5c700e65ecb0 to your computer and use it in GitHub Desktop.
Common Gulpfile for ASP.NET Core web app which uses bootstrap.
"use strict";
var gulp = require('gulp');
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*', 'main-bower-files', 'del'],
replaceString: /\bgulp[\-.]/
});
// configuration
var config = {
scripts: {
bundle: 'site.min.js',
dest: 'wwwroot/dist/js/',
glob: '**/*.js'
},
styles: {
bundle: 'site.min.css',
dest: 'wwwroot/dist/css/',
src: ['bower_components/bootstrap/dist/css/bootstrap.css', 'wwwroot/css/*']
},
fonts: {
dest: 'wwwroot/dist/fonts/',
src: ['bower_components/**/*.{eot,svg,ttf,woff,woff2}']
},
distribution: 'wwwroot/dist/**/*'
}
// tasks
gulp.task('clean', function () {
return plugins.del([config.distribution]);
});
gulp.task('scripts', function () {
return gulp.src(plugins.mainBowerFiles(config.scripts.glob))
.pipe(plugins.concat(config.scripts.bundle))
.pipe(plugins.uglify())
.pipe(gulp.dest(config.scripts.dest));
});
gulp.task('styles', function () {
return gulp.src(config.styles.src)
.pipe(plugins.concat(config.styles.bundle))
.pipe(plugins.cleanCss())
.pipe(gulp.dest(config.styles.dest));
});
gulp.task('fonts', function() {
return gulp.src(config.fonts.src)
.pipe(plugins.flatten())
.pipe(gulp.dest(config.fonts.dest));
});
gulp.task('build', ['scripts', 'styles', 'fonts']);
gulp.task('default', ['clean'], function() {
gulp.start('build');
});
gulp.task('watch', function() {
gulp.watch('wwwroot/css/site.css', ['styles']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment