Created
April 28, 2020 14:03
-
-
Save luis-fss/315ae484c98440506bb5427eb20520e0 to your computer and use it in GitHub Desktop.
NPM and Gulp for Asp.Net Core 3 config sample
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
/// <binding AfterBuild='default' Clean='clean' /> | |
/* | |
This file is the main entry point for defining Gulp tasks and using Gulp plugins. | |
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007 | |
*/ | |
var gulp = require('gulp'); | |
var del = require('del'); | |
var plumber = require('gulp-plumber'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var uglify = require('gulp-uglify'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var merge = require('merge-stream'); | |
var nodeRoot = './node_modules/'; | |
var wwwroot = './wwwroot/'; | |
var libTargetPath = wwwroot +'lib/'; | |
var jsBundleTarget = wwwroot + 'js/bundle/'; | |
var mainJSLib = { | |
sources: [ | |
nodeRoot + "jquery/dist/jquery.js", | |
nodeRoot + "bootstrap/dist/js/bootstrap.bundle.js", | |
wwwroot + "js/**/*.js" | |
], | |
dest: libTargetPath + "main/js" | |
}; | |
var validationJSLib = { | |
sources: [ | |
nodeRoot + "jquery-validation/dist/jquery.validate.js", | |
nodeRoot + "jquery-validation-unobtrusive-bootstrap/dist/unobtrusive-bootstrap.js" | |
], | |
dest: libTargetPath + "validation/js" | |
}; | |
var libFiles = [ mainJSLib, validationJSLib ]; | |
var appBundles = [ | |
{ sources: [ libTargetPath + "main/js/**/*.js" ], output: 'site.main.bundle.js' }, | |
{ sources: [ libTargetPath + "validation/js/**/*.js" ], output: 'site.validation.bundle.js' } | |
]; | |
function clean() { | |
return del([libTargetPath + '/**/*', jsBundleTarget + '/**/*']); | |
} | |
function moveLibFiles() { | |
var streams = []; | |
libFiles.forEach(function (libFile) { | |
console.log('Moving lib files from: ' + libFile.sources + ' into: ' + libFile.dest); | |
var stream = gulp.src(libFile.sources) | |
.pipe(plumber()) | |
.pipe(gulp.dest(libFile.dest)) | |
.on('error', errorHandler); | |
streams.push(stream); | |
}); | |
return merge.apply(this, streams); | |
}; | |
function minify() { | |
var streams = []; | |
appBundles.forEach(function (appBundle) { | |
console.log('Creating minified files for: ' + appBundle.sources + ' into: ' + jsBundleTarget + appBundle.output); | |
var stream = gulp.src(appBundle.sources) | |
.pipe(plumber()) | |
.pipe(concat(appBundle.output)) | |
.pipe(rename({ extname: '.min.js' })) | |
.pipe(uglify()) | |
.pipe(gulp.dest(jsBundleTarget)) | |
.on('error', errorHandler); | |
streams.push(stream); | |
}); | |
return merge.apply(this, streams); | |
} | |
function bundle() { | |
var streams = []; | |
appBundles.forEach(function (appBundle) { | |
console.log('Creating bundle and sourcemaps: ' + jsBundleTarget + appBundle.output); | |
var stream = gulp.src(appBundle.sources) | |
.pipe(plumber()) | |
.pipe(concat(appBundle.output)) | |
.pipe(sourcemaps.init()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest(jsBundleTarget)) | |
.on('error', errorHandler); | |
streams.push(stream); | |
}); | |
return merge.apply(this, streams); | |
}; | |
function errorHandler(error) { | |
console.error(error.toString()); | |
process.exit(-1); | |
} | |
exports.default = gulp.series(clean, moveLibFiles, minify, bundle); |
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
{ | |
"version": "1.0.0", | |
"name": "aspnetmvc", | |
"private": true, | |
"devDependencies": { | |
"del": "^5.1.0", | |
"gulp": "^4.0.2", | |
"gulp-concat": "^2.6.1", | |
"gulp-plumber": "^1.2.1", | |
"gulp-rename": "^2.0.0", | |
"gulp-sourcemaps": "^2.6.5", | |
"gulp-uglify": "^3.0.2", | |
"merge-stream": "^2.0.0" | |
}, | |
"dependencies": { | |
"bootstrap": "^4.4.1", | |
"cldr-data": "^36.0.0", | |
"cldr": "^5.6.0", | |
"globalize": "^1.5.0", | |
"jquery-mask-plugin": "^1.14.16", | |
"jquery-validation-globalize-fix": "^0.1.1", | |
"jquery-validation-unobtrusive-bootstrap": "^2.2.0", | |
"jquery-validation": "^1.19.1", | |
"jquery": "^3.5.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment