ASP.NET 5ã®ã³ã©ã ã§ã¯ããŠã¯ã©ã€ãã®ä»£è¡šã§ããDmitry Ubraniansã® Dmitry Sikorskyã«ããåºçç©ãç¶ããŠããŸãã ãã®èšäºã§ã¯ãDmitryãã人æ°ã®ããGulpããŒã«ã®ASP.NET 5ã䜿çšããã¢ããªã±ãŒã·ã§ã³ã·ããªãªã«ã€ããŠè©³ãã説æããŠããŸãã ãã®ã³ã©ã ã®ä»¥åã®èšäºã¯ã ïŒaspnetcolumn -Vladimir Yunevã§ãã€ã§ãèªãããšãã§ããŸããASP.NET 5以åã¯ãGulpã®ãããªããŒã«ã䜿çšããããšããªãã£ãããããã®ãã©ãããã©ãŒã ã§æåã®ãããžã§ã¯ããäœæãããšãã®æéãææ¡ããªããã°ãªããŸããã§ããïŒåœæã¯ãŸã GruntããããŸããããéèŠïŒã ãã§ã«ååã«è©³çŽ°ã«èª¬æãããŠããåºæ¬çãªããšã¯è¡ããŸããïŒãããžã§ã¯ãã«ã¯æ¢ã«Gulpfile.jsããããVisual Studio 2015ã®ã¿ã¹ã¯å®è¡ãããŒãžã£ãŒã䜿çšããŠã¿ã¹ã¯ãå®è¡ã§ããããšãæå³ããŸãïŒå®éã«ãGulpã䜿çšããŠASP.NET 5ãããžã§ã¯ãã®ãã¹ãŠãèªååããæ¹æ³ã玹ä»ããŸãã
ãã®èšäºã§ã¯ãAspNet5Gulpizationãã¹ããããžã§ã¯ãã®Gulpfile.jsãã¡ã€ã«ã®ãã©ã°ã¡ã³ããæäŸããŸã ããã®ãããžã§ã¯ãã¯ãå®å šã«https://github.com/DmitrySikorsky/AspNet5Gulpizationã«ãããŸã ã
ãšã³ããªãŒ
æ°ããwwwrootãã©ã«ããŒã®çšéããåç¥ã§ãããã å®éã圌女ã®å€èŠ³ã§ã¯ãã¹ã¯ãªãããã¹ã¿ã€ã«ãåçãå°ãæ°ããæ¹æ³ã§èŠãŸããã ã€ãŸãããµã€ãã®ãµãŒããŒã®ã³ãŒãã®ããã«ããœãŒã¹ãšå ¬éã®æºåãã§ãããªããžã§ã¯ãã«åããŸãã
æºåãã
ã¢ããã€ã¹ïŒ ãã¹ãŠãè©ŠãããGitHub https://github.com/DmitrySikorsky/AspNet5GulpizationãããœãŒã¹ã³ãŒããããŠã³ããŒãããŠãã ãã ãæåã«ãã¿ã¹ã¯ã§äœ¿çšãããã¹ãŠã®ããã±ãŒãžãGulpãã¡ã€ã«ã«ãªã¹ãããå¿ èŠããããŸãïŒãããŠããããããã¹ãŠpackage.jsonã«ååšããããšã確èªããŠãã ããïŒã
var gulp = require("gulp"), autoprefixer = require("gulp-autoprefixer"), concat = require("gulp-concat"), del = require("del"), minifyCss = require("gulp-minify-css"), rename = require("gulp-rename"), runSequence = require("run-sequence"), sass = require("gulp-sass"), tsc = require("gulp-tsc"), uglify = require("gulp-uglify");
ããã«ããœãŒã¹ãã¡ã€ã«ãšçµæãã¡ã€ã«ããã¹ãŠ1ã€ã®å Žæã§ç·šéã§ããããã«ããªããžã§ã¯ãã®åœ¢åŒã®ãã¹ãè¡šããšéåžžã«äŸ¿å©ã§ãã
var paths = { frontend: { scss: { src: [ "styles/*.scss" ], dest: "wwwroot/css" }, ts: { src: [ "scripts/*.ts" ], dest: "wwwroot/js" } }, shared: { bower: { src: "bower_components", dest: "wwwroot/lib" } } }
æåŸã«ããã¹ãŠã®ã¹ã¯ãªãããšã¹ã¿ã€ã«ãåæ§ç¯ããããããåŠçããŠãçµæã®ãã©ã«ããŒã«ã³ããŒããã¡ã€ã³ã®Gulpã¿ã¹ã¯ã«ã€ããŠèª¬æããŸãã
gulp.task( "rebuild", function (cb) { runSequence( "clean", "build", "minify", "delete-unminified", "rename-temp-minified", "delete-temp-minified", cb ); } );
runSequenceããã±ãŒãžã䜿çšãããšãã¿ã¹ã¯ã次ã ãšé çªã«å®è¡ã§ããŸãããã®å Žåãããã¯éåžžã«éèŠã§ãã ãŸããcbã³ãŒã«ããã¯é¢æ°ãã·ãŒã±ã³ã¹ã®æåŸã®ã¿ã¹ã¯ãšããŠæž¡ããŠãåŒã³åºãã³ãŒãã«ããã»ã¹å šäœã®å®äºãéç¥ã§ããããã«ããŠãã ããã
ã¡ãªã¿ã«ãæåã§åæ§ç¯ã¿ã¹ã¯ãå®è¡ããªãããã«ããã«ã¯ããããžã§ã¯ãããã«ããŸãã¯éããšãã«ã¹ã¿ãžãªã«åŒ·å¶çã«å®è¡ãããããGulpãã¡ã€ã«ã«çŽæ¥å¥ã®ã¿ã¹ã¯ãè¿œå ãïŒãããžã§ã¯ããéããšãã«èªåçã«å®è¡ïŒããªã¹ããŒãèšå®ããŠãœãŒã¹ãã¡ã€ã«ãå€æŽãããã®ãããªå€æŽãæ€åºããããã¿ã¹ã¯ãå®äºããŸãã
ã¹ã¯ãªãã
ç§ã¯ããã®ã·ã³ãã«ããšåªé ãã§JavaScriptãæ¬åœã«æããŸããïŒãããŠãããããããã§ãïŒã çŸåšãTypeScriptã倧奜ãã§ãã ïŒããã¯çŽ æŽãããããŒã«ã§ãã泚æããããšããå§ãããŸããïŒéåžžããã¹ãŠã®tsãã¡ã€ã«ãScriptsãã©ã«ããŒã«ä¿åããŸããããããžã§ã¯ãã®å ¬éæã«ã¯ç¡èŠãããŸãã ãããã¯ãã¯ã©ã€ã¢ã³ãã¹ã¯ãªããã®ãœãŒã¹ã³ãŒãã§ãã æåã«TypeScriptãJavaScriptã«ã³ã³ãã€ã«ãããããå§çž®ããŠãã1ã€ã®ãã¡ã€ã«ã«æ¥çããæçµçã«çµæãã¡ã€ã«ãwwwroot / jsãã©ã«ããŒã«ã³ããŒããŠãã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšããã¿ã¹ã¯ãGulpãã¡ã€ã«ã«èšå®ããŸãã ïŒTypeScriptã䜿çšããŠããªãå Žåã¯ãåã«JavaScriptã«å€æããæé ãã¹ãããã§ããŸããæ®ãã®ã¿ã¹ã¯ã¯å€æŽããã«åäœããŸããïŒ
æ¢å®ã§ã¯ãVisual Studio 2015ã¯ä¿åæã«tsãã¡ã€ã«ãã³ã³ãã€ã«ããçµæã®jsãã¡ã€ã«ãåããã©ã«ããŒã«é 眮ããŸãã ãã®åäœã¯å¿ èŠãªãããããããžã§ã¯ãèšå®ã§TypeScriptã³ã³ãã€ã«ãç¡å¹ã«ããŸãã
TypeScriptãã³ã³ãã€ã«ãããžã§ãã¯æ¬¡ã®ããã«ãªããŸãã
gulp.task( "frontend:build-ts", function (cb) { return gulp.src(paths.frontend.ts.src) .pipe(tsc()) .pipe(gulp.dest(paths.frontend.ts.dest)); } );
ãã®ãããçµæã®JavaScriptãå§çž®ããŠã1ã€ã®çµæãã¡ã€ã«ã«è²Œãä»ããããšãã§ããŸãã
gulp.task( "frontend:minify-js", function (cb) { return gulp.src(paths.frontend.ts.dest + "/*.js") .pipe(uglify()) .pipe(concat("aspnet5gulpization.min.js.temp")) .pipe(gulp.dest(paths.frontend.ts.dest)); } );
å€ãã®jsãã¡ã€ã«ã1ã€ã«è²Œãä»ãããšãçµæã®ãã¡ã€ã«ã«ééã£ãé åºã§è¿œå ãããå®çŸ©ãåŒã³åºãåŸã«é 眮ããããããå®çŸ©ãããŠããªããšããã¡ãã»ãŒãžã衚瀺ãããå¯èœæ§ããããŸãã ãããçºçããå Žåãçµæãã¡ã€ã«ã®ã¹ã¯ãªããã®é åºãæåã§ç°¡åã«èšå®ã§ããŸãã æåã«åŸãå¿ èŠãããã¹ã¯ãªãããå¿ èŠãªé åºã§ãªã¹ãããããšãã§ããé åã®æåŸã®èŠçŽ ãšåããã©ã«ãã瀺ãã ãã§ãGulpã¯æ瀺çã«æå®ããããã¡ã€ã«ãæåã«ãã©ã«ãããåŠçããæ®ãããã¹ãŠåŠçããå¿ èŠããããšæšæž¬ããŸãã
ã¡ãªã¿ã«ãNPMããã±ãŒãžã埩å ããéã«ãšã©ãŒã¡ãã»ãŒãžãçªç¶è¡šç€ºãããå ŽåïŒãªãã·ã§ã³ã§ãåæãããäžé£ã®æåã§æ§æãããæèšã䜿çšïŒããŸãã¯ããã±ãŒãžã埩å ããããšãããšVisual Studio 2015ãåã«ã¯ã©ãã·ã¥ããå Žåãããã¯ãã¡ã€ã«ã·ã¹ãã å ã®ãããžã§ã¯ãã®ãã¹ãã®æ·±ãã«ããå¯èœæ§ããããŸãã ïŒäžéšãããã«é¢ããæ å ±ã¯ããã§èŠã€ããŸããïŒ https : //github.com/Microsoft/nodejstools/issues/336 ïŒå°ãæéãè²»ãããåŸãå°ãªããµããã©ã«ããŒã«ç©ºã®ãããžã§ã¯ããäœæããããã«package.jsonãã³ããŒããããã«åŸ©å ããŸããããã±ãŒãžããnode_modulesãã©ã«ããŒãšå ±ã«ãããžã§ã¯ãã«è»¢éããŸãã ãŸããã¹ã¿ãžãªã®åŽ©å£äžã«ãç Žæããããã±ãŒãžãnpm-cacheãã©ã«ããŒã«å ¥ãå¯èœæ§ããããããããã念é ã«çœ®ããŠãå¿ èŠã«å¿ããŠããããåé€ããå¿ èŠããããŸãã
ã¹ã¿ã€ã«
æè¿ã§ã¯ãSCSSãè©Šãããšã«ããŸããã äž»ãªç®æšã¯ãæ€çŽ¢ãšçœ®æã䜿çšããã®ã§ã¯ãªããè²ãªã©ã1ãæã§ç·šéã§ããããã«ããããšã§ããã ãŸãã巚倧ãªcssãã¡ã€ã«ãè€æ°ã®éšåã«åå²ããããšã¯çŽ æŽãããããšã§ãããšå€æããŸãããããã«ããããããã䌎ãã®ããã䟿å©ã«ãªããŸãïŒç§ã®æèŠã§ã¯ããã€æšãŠãé¿ããªããã¹ã¿ã€ã«ã䌎ãããšã¯éåžžã«å°é£ã§ããäžç®ã§å¿ ãããæããã§ã¯ãããŸããïŒã SCSSã䜿çšãããšè¯ãçµæãåŸãããŸããã
TypeScriptãšåæ§ã«ãç§ã®Gulpãã¡ã€ã«ã«ã¯ãSCSSãCSSã«ã³ã³ãã€ã«ãããã³ããŒãã¬ãã£ãã¯ã¹ãè¿œå ããçµæãã¡ã€ã«ãwwwroot / cssãã©ã«ããŒã«å§çž®ãæ¥çãã³ããŒããã¿ã¹ã¯ãå«ãŸããŠããŸãã
CSSã§ã®SCSSã®ã³ã³ãã€ã«ã¯æ¬¡ã®ãšããã§ãã
gulp.task( "frontend:build-scss", function (cb) { return gulp.src(paths.frontend.scss.src) .pipe(sass()) .pipe(gulp.dest(paths.frontend.scss.dest)); } );
ããŠãå§çž®ãæ¥çïŒãã³ããŒãã¬ãã£ãã¯ã¹ã®åæé 眮ïŒïŒ
gulp.task( "frontend:minify-css", function (cb) { return gulp.src(paths.frontend.scss.dest + "/*.css") .pipe(minifyCss()) .pipe(autoprefixer("last 2 version", "safari 5", "ie 8", "ie 9")) .pipe(concat("aspnet5gulpization.min.css.temp")) .pipe(gulp.dest(paths.frontend.scss.dest)); } );
å³æžé€š
ããšãã°ãASP.NET 5ãããžã§ã¯ãã§jQueryãå¿ èŠãªå Žåã¯ãã»ãšãã©ã®å ŽåBowerã䜿çšããŠããŠã³ããŒãããŸãã以åã«äœ¿çšããNuGetãšã¯ç°ãªããjquery.min.jsãã¡ã€ã«ãš2ã€ä»¥äžã®ãã¡ã€ã«ãååŸããŸãããã®ä»ã jqueryãã©ã«ããŒã¯bower_componentsãã©ã«ããŒã«äœæãããŸãããã®ãã©ã«ããŒã«ã¯ãäžèšã®ãã¡ã€ã«ã«å ããŠãã©ã€ãã©ãªã®éå§çž®ããŒãžã§ã³ãšãã®ãœãŒã¹ããããŸãïŒãã¡ãããå ¬éäžã¯ç¡èŠãããŸãïŒã
èããŠã¿ãã°ããããã®ã©ã€ãã©ãªãå°ãªããšã2ã€ã®æ¹æ³ã§äœ¿çšã§ããŸãã
ãŸããjquery.min.jsãã¡ã€ã«ãæåã«wwwroot / lib / jqueryãã©ã«ããŒã«ã³ããŒããŠãããŒãžã«æ¥ç¶ããã ãã§ãã ããã¯ç§ããã£ãããšã§ãïŒGoogle Hosted Librariesã®ãããªãµãŒãã¹ãããæ£ç¢ºã«äœ¿çšããããšã¯ã§ããŸããããã®ããããã©ãŠã¶ã¯å¥ã®ãµã€ãã«ã¢ã¯ã»ã¹ãããšãã«ãããŠã³ããŒãããã®ã§ã¯ãªããã©ã€ãã©ãªãªãã·ã§ã³ããã£ãã·ã¥ããŸãããã»ãšãã©ã®å Žåã¯ããããŸããïŒã
次ã«ãã©ã€ãã©ãªã®éå§çž®ããŒãžã§ã³ïŒjquery.jsïŒãååŸããã¢ããªã±ãŒã·ã§ã³å ã®ä»ã®ã¹ã¯ãªãããåŠçãããã®ãšåãæ¹æ³ã§åŠçã§ããŸãã ã€ãŸããçµæãšããŠãåäžã®å ±éjsãã¡ã€ã«ã«è¿œå ããWebãµãŒããŒãžã®ãªã¯ãšã¹ãã®æ°ãæžãããŸãã
3ã€ã®ã©ã€ãã©ãªã«å¿ èŠãªãã¡ã€ã«ãã³ããŒããã¿ã¹ã¯ã¯æ¬¡ã®ãšããã§ãã
gulp.task( "lib-copy", function (cb) { var lib = { "/jquery": "/jquery/dist/jquery*.{js,map}", "/jquery-validation": "/jquery-validation/dist/jquery.validate*.js", "/jquery-validation-unobtrusive": "/jquery-validation-unobtrusive/jquery.validate.unobtrusive*.js" }; for (var $package in lib) { gulp .src(paths.shared.bower.src + lib[$package]) .pipe(gulp.dest(paths.shared.bower.dest + $package)); } cb(); } );
çµè«
ç§ã¯çµæã奜ãã§ãã ã¹ã¿ã€ã«ãšã¹ã¯ãªãããç°¡åãã€äŸ¿å©ã«æäœããå ¬éåã«ããããç°¡åãã€äŸ¿å©ã«æé©åããŠãããã»ã¹ãå®å šã«å¶åŸ¡ã§ããããšãæ°ã«å ¥ã£ãŠããŸãã ãã¡ãããããã¯Gulpãæ¯æŽã§ããå¯äžã®æ¹æ³ã§ã¯ãããŸãããããã®æ©èœãå®å šã«ç解ããã«ã¯ããã§ååã ãšæããŸãã
èè åã
ãå人ããèªèº«ã®è³æã§ã³ã©ã ããµããŒãããããšã«èå³ãããå Žåã¯ããã¹ãŠã®è©³çŽ°ãè°è«ããããã«vyunev@microsoft.comãŸã§ãé£çµ¡ãã ããã ASP.NETããã³ãã®ä»ã®ãããã¯ã«ã€ããŠèå³æ·±ã話ãã§ããèè ãæ¢ããŠããŸãã
èè ã«ã€ããŠ
ã·ã³ã«ã¹ããŒã»ããããªãŒã»ã¢ã¬ã¯ãµã³ãããŽã£ã
Ubrainians CompanyïŒhttp://ubrainians.com/ïŒ
ãªãŒããŒããããŒãžã£ãŒ
ããããªãŒã·ã³ã«ã¹ããŒ