Last active
November 23, 2015 20:09
-
-
Save notpeelz/dd1d98f1687a2e521b9b to your computer and use it in GitHub Desktop.
ASP.NET MVC Gulpfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var bowerFiles = require('gulp-main-bower-files'); | |
var runSequence = require('run-sequence').use(gulp); | |
// Preprocessor & plugins | |
var plugins = require('gulp-load-plugins')({ camelize: true, lazy: true }); | |
var precss = require('precss'); | |
var autoprefixer = require('autoprefixer'); | |
var mqpacker = require('css-mqpacker'); | |
var csswring = require('csswring'); | |
var cssnano = require('cssnano'); | |
var discardComments = require('postcss-discard-comments'); | |
var postcssSize = require('postcss-size'); | |
var postcssCalc = require("postcss-calc"); | |
var fontMagician = require('postcss-font-magician'); | |
// Miscellaneous modules | |
var ss = require('stream-series'); | |
var es = require('event-stream'); | |
var del = require('del'); | |
// Load Promise polyfill (PostCSS dependency fix) | |
require('es6-promise').polyfill(); | |
// Node API modules | |
var nl = { | |
path: require('path') | |
} | |
var knownOptions = { | |
string: ['env'], | |
alias: { environment: 'env' }, | |
default: { env: process.env.NODE_ENV || 'development' } | |
}; | |
var argv = require('minimist')(process.argv.slice(2), knownOptions); | |
var getBowerFiles = function () { | |
return bowerFiles({ | |
"overrides": { | |
"jquery-validation-unobtrusive": { | |
"main": argv.environment === 'development' ? [ | |
"jquery.validate.unobtrusive.js" | |
] : [ | |
"jquery.validate.unobtrusive.min.js" | |
] | |
}, | |
"bootstrap": { | |
"main": argv.environment === 'development' ? [ | |
"./dist/js/bootstrap.js", | |
"./dist/css/bootstrap.css", | |
"./dist/fonts/*.*" | |
] : [ | |
"./dist/js/bootstrap.min.js", | |
"./dist/css/bootstrap.min.css", | |
"./dist/fonts/*" | |
] | |
}, | |
"components-font-awesome": { | |
"main": argv.environment === 'development' ? [ | |
"./css/font-awesome.css", | |
"./fonts/*.*" | |
] : [ | |
"./css/font-awesome.min.css", | |
"./fonts/*.*" | |
] | |
}, | |
"respond": { | |
"main": argv.environment === 'development' ? [ | |
"./dist/respond.src.js" | |
] : [ | |
"./dist/respond.min.js" | |
] | |
}, | |
"modernizr": { | |
"main": [ | |
"./modernizr.js" | |
] | |
}, | |
"ekko-lightbox": { | |
"main": argv.environment === 'development' ? [ | |
"./dist/ekko-lightbox.js", | |
"./dist/ekko-lightbox.css" | |
] : [ | |
"./dist/ekko-lightbox.min.js", | |
"./dist/ekko-lightbox.min.css" | |
], | |
"dependencies": { | |
"bootstrap": ">= 3.0.0", | |
"jquery": ">= 1.7.3" | |
} | |
} | |
} | |
}); | |
} | |
gulp.task('watch', function() { | |
plugins.watch(['./src/css/**/*.*css', './src/js/**/*.js'], plugins.batch(function (events, done) { | |
gulp.start('build', done); | |
})); | |
}); | |
gulp.task('clean-all', function () { | |
del.sync(['./build/**', '!./build', './static/**', '!./static']); | |
}); | |
gulp.task('build-styles', function () { | |
var processors = [ | |
precss({ | |
"import": { | |
"extension": "scss" | |
} | |
}), | |
postcssCalc, | |
postcssSize, | |
autoprefixer({ browsers: ['last 10 version'] }), | |
mqpacker, | |
fontMagician | |
]; | |
return gulp.src('./src/css/**/*.*css') | |
.pipe(plugins.postcss(processors)) | |
.pipe(gulp.dest('./build/css')); | |
}); | |
gulp.task('build-scripts', function () { | |
return gulp.src('./src/js/**/*.js') | |
.pipe(gulp.dest('./build/js')); | |
}); | |
gulp.task('build-misc', function () { | |
return gulp.src(['./src/img/**/*', './src/fonts/**/*'], { base: './src' }) | |
.pipe(gulp.dest('./static')); | |
}); | |
gulp.task('build-content', function () { | |
var isDevelopment = argv.environment === 'development'; | |
var jsFilter = plugins.filter(isDevelopment ? 'build/js/**/*.js' : '**/*.js', { restore: true }); | |
var cssFilter = plugins.filter(isDevelopment ? 'build/css/**/*.*css' : '**/*.*css', { restore: true }); | |
var fontFilter = plugins.filter('**/fonts/**/*', { restore: true }); | |
return gulp.src('./Views/**/*.cshtml') | |
.pipe(plugins.inject( | |
ss(gulp.src('./bower.json') | |
.pipe(getBowerFiles()) | |
.pipe(plugins.rename(function (path) { | |
var pathParts = path.dirname.split(nl.path.sep); | |
if (/d[ie]st/g.test(pathParts.splice(1, 1))) | |
path.dirname = nl.path.join.apply(null, pathParts); | |
})) | |
.pipe(plugins.if(isDevelopment, gulp.dest('./static/vendor'))) | |
.pipe(fontFilter) | |
.pipe(plugins.if(!isDevelopment, plugins.rename({ dirname: '' }))) | |
.pipe(plugins.if(!isDevelopment, gulp.dest('./static/fonts'))) | |
.pipe(fontFilter.restore), | |
gulp.src(['./build/js/pre/*.js', './build/js/dummy.js'], { base: './' }), | |
gulp.src(['./build/css/**/*.*css', '!./build/css/**/_*.*css'], { base: './' })) | |
//.pipe(plugins.debug({ title: 'pre-filter:' })) | |
.pipe(cssFilter) | |
//.pipe(plugins.debug({ title: 'post-filter:' })) | |
.pipe(plugins.if(!isDevelopment, plugins.postcss([cssnano(), discardComments(), csswring]))) | |
.pipe(plugins.if(!isDevelopment, plugins.concat('style.min.css'))) | |
.pipe(plugins.rename({ dirname: '', extname: '.css' })) | |
.pipe(gulp.dest('./static/css')) | |
.pipe(cssFilter.restore) | |
.pipe(jsFilter) | |
.pipe(plugins.if(!isDevelopment, plugins.concat('script.min.js'))) | |
.pipe(plugins.if(!isDevelopment, plugins.uglify())) | |
.pipe(plugins.rename({ dirname: '' })) | |
.pipe(gulp.dest('./static/js')) | |
.pipe(jsFilter.restore), { name: 'main' })) | |
.pipe(plugins.inject(gulp.src('./build/js/post/*.js') | |
.pipe(plugins.if(!isDevelopment, plugins.concat('script.min.js'))) | |
.pipe(plugins.if(!isDevelopment, plugins.uglify())) | |
.pipe(gulp.dest('./static/js/post')), { name: 'post' })) | |
.pipe(gulp.dest('./Views/')); | |
}); | |
gulp.task('build', function () { | |
runSequence('clean-all', ['build-scripts', 'build-styles', 'build-misc'], 'build-content'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pas mal cool