Skip to content

Instantly share code, notes, and snippets.

@aosteraas
Created September 7, 2017 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aosteraas/6ee968c9ccc17556e8491f51748e4e6c to your computer and use it in GitHub Desktop.
Save aosteraas/6ee968c9ccc17556e8491f51748e4e6c to your computer and use it in GitHub Desktop.
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const autoprefix = require('gulp-autoprefixer');
const notify = require('gulp-notify');
const concat = require('gulp-concat');
const order = require('gulp-order');
const uglify = require('gulp-uglify');
const pump = require('pump');
const jshint = require('gulp-jshint');
const paths = {
webroot: './wwwroot',
cssIn: './Styles/**/*.scss',
cssOut: './wwwroot/css',
jsIn: './Scripts/**/*.js',
jsOut: './wwwroot/js',
jsLintable: './Scripts/site/*.js'
}
const autoprefixOptions = {
browsers: ['last 2 versions']
};
gulp.task('css', () => {
gulp.src('./Styles/styles.scss')
.pipe(sourcemaps.init())
.pipe(autoprefix(autoprefixOptions))
.pipe(sass({outputStyle: 'compressed'}))
.pipe(sourcemaps.write('/sourcemaps'))
.pipe(gulp.dest(paths.cssOut));
});
gulp.task('jslint', () => {
gulp.src(paths.jsLintable)
.pipe(jshint({
browser: true,
curly: true,
devel: true,
eqeqeq: true,
globals: {
jQuery: true,
},
strict: "implied", // lint *as if* all files have use strict in top
undef: true,
unused: "vars" // only check for vars, not func params, disable with /* jshint unused:false */
// Note: some vars (generally jQ$s) are explicty set but never used to make it
// more obvious what jQ element is being effected by the call at the end
}))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('js', ['jslint'], () => {
pump([
gulp.src(paths.jsIn),
sourcemaps.init(),
order([
'/Scripts/site/site-utils.js'
], { base: '.' }),
uglify({ mangle: false }),
concat('scripts.min.js'),
sourcemaps.write('/sourcemaps'),
gulp.dest(paths.jsOut)
]);
});
gulp.task('watch', ['css', 'js'], () => {
gulp.watch(paths.cssIn, ['css']);
gulp.watch(paths.jsIn, ['js']);
});
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment