Last active
January 20, 2021 14:28
-
-
Save brakmic/49affaaaf5c1760186d2 to your computer and use it in GitHub Desktop.
Visual Studio (MSBuild) + Webpack + LiveReload with Gulp
This file contains 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
/* jshint strict : false */ | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var plumber = require('gulp-plumber'); | |
var webpack = require('webpack'); | |
var msbuild = require("gulp-msbuild"); | |
var nodemon = require('nodemon'); | |
var webpackConfigPath = require('./webpack.config'); | |
var vsSolutionPath = 'PATH_TO_VISUAL_STUDIO_SOLUTION'; | |
var watchPaths = [ | |
'Scripts/**/*.js', | |
'Content/**/*.css' | |
]; | |
var gulpIgnore = require('gulp-ignore'); | |
var livereload = require('gulp-livereload'); /* install the Chrome LiveReload plugin and activate it*/ | |
var webpackInst = webpack(webpackConfigPath); | |
/* after the webpack task the reload plugin will kick in and refresh the browser */ | |
/* (livereload-plugin works in Chrome only) */ | |
gulp.task('webpack', function(cb) { | |
webpackInst.run(function(err, stats) { | |
if(err) { | |
throw new gutil.PluginError('webpack', err); | |
} | |
gutil.log('[webpack]', stats.toString()); | |
cb(); | |
livereload.reload(); | |
}); | |
}); | |
/* check the config info of "msbuild" for more details regarding the VS flags */ | |
/* Git: https://github.com/hoffi/gulp-msbuild */ | |
gulp.task("msbuild", function() { | |
return gulp.src(vsSolutionPath) | |
.pipe(plumber()) | |
.pipe(msbuild({ | |
stdout : true, | |
targets : ['Clean','Build'], // clean cruft an build | |
toolsVersion : 12.0, //use Visual Studio 2013 | |
nologo : false, | |
configuration : 'Debug', // change to "Release" when deploying to prod | |
verbosity : 'quiet', | |
properties : { WarningLevel: 1 }, // errors only | |
platform : process.platform, | |
architecutre : 'x64', | |
errorOnFail : true // halt Gulp when msbuild fails | |
}) | |
); | |
}); | |
gulp.task('watch', function() { | |
livereload.listen(); // must be called once to activate livereload | |
gulp.watch(watchPaths, ['webpack']); //watch for changes and activate webpack accordingly | |
}); | |
gulp.task('run', ['watch'], function() { // run current build and watch for changes | |
nodemon({ | |
execMap: { | |
js: 'node --harmony' | |
}, | |
script: 'index.js', | |
ext: 'noop' | |
}).on('restart', function() { | |
console.log('restarted!'); | |
}); | |
}); | |
gulp.task('all', ['msbuild','webpack']); | |
gulp.task('default', ['all']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment