ã¯ããã«
æåã®ASP.NET Coreã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒãïŒVisual Studioããã®ãããã°ã§åäœããŸãïŒã«åºã¥ããŠãnpmãWebpackãããã³TypeScriptããµããŒãããæå°éã®ã¢ããªã±ãŒã·ã§ã³ããã°ããäœæã§ããããã«ããããã«ãç§ã¯äž»ã«èªåçšã«ãã®ãã¥ãŒããªã¢ã«ãæžããŠããŸãã
ããæ°
ç§ã¯ãç¹ã«WebãšJavaScriptãåããŠã§ãã ãã ããç§ã¯åžžã«.Netã䜿çšããŠããŸãã ãŸããJavaScriptãšãã®äžã«ããããããçš®é¡ã®ãã¬ãŒã ã¯ãŒã¯ãç¥ã£ãŠããŠãä»ã§ã¯ã¹ã¿ã€ãªãã·ã¥ã§ãã¡ãã·ã§ããã«ã§ãæ±ãã®ããã«è¥ã ãããšæããŸãã ãããã次ã®ã©ã€ãã©ãªãæããããã«ã¯ãååãšããŠæ©èœããããã«ãéåžžã¯ãã¹ãŠã®ãã®ãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
éåžžããµãŒããŒïŒnode.jsãä»ããŠïŒãnpmãããã³Webpackã®ãããªãã®ïŒLess for workãŸãã¯äœããã®ãã³ãã¬ãŒã/ãããã¡ã€ã¢ãŒïŒãå¿ èŠã§ãã ASP.NETãå°ãéžãã§ïŒã³ã¢ã§ã¯ãªãéåžžïŒããµãŒããŒåŽã®å¯ŸåŠæ¹æ³ã倧ãŸãã«æ³åã§ããŸãããããã³ããšã³ãã¯ç§ã«ãšã£ãŠæã森ã§ãã
åé¡ã¯ãWebäžã®æè¡ã¯éåžžASP.NETã§ã¯ãªããnode.jsãphpãããã³ãã®ä»ã®äž»æµã«çŠç¹ãåœãŠãŠããããšã§ãã ãŸããããã¥ã¡ã³ãã®äŸã¯ãã¹ãŠã®äººã«ãšã£ãŠåžžã«ããã«åºã¥ããŠãããASP.NETãæåããèšå®ããã®ã¯ããã»ã©ç°¡åã§ã¯ãããŸããã
ãã®ãã¥ãŒããªã¢ã«ã§ã¯ãASP.NET Coreã®ãã³ãã¬ãŒãã®æ°ãããããžã§ã¯ãããæå°éã®äœæ¥ã¢ããªã±ãŒã·ã§ã³ãäœæããæ¹æ³ã瀺ããŸãã
- npm -JavaScriptã§ããŸããŸãªã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããå¿ èŠããããã©ãã§ãå¿ èŠã§ãã
- Webpack -JavaScriptããã®ä»ã®ã³ã³ãã³ããããã±ãŒãžåãçž®å°ãããã©CSSã®ä»£ããã«Lessã䜿çšãHTMLãã³ãã¬ãŒããšã³ãžã³ã䜿çšãJavaScriptãã©ã³ã¹ãã€ã©ãŒãªã©ã䜿çšããå¿ èŠãããå Žåã«å¿ èŠã§ãã
- TypeScript-æ°ããããŒãžã§ã³ã®JavaScriptããå€ãããŒãžã§ã³ãžã®ãã©ã³ã¹ããŒã¿ãŒãšããŠäœ¿çšã§ããŸãã TypeScriptèšèªèªäœã䜿çšããããšãã§ããŸãã 2ã€ã1ã€ã«ãªã£ãŠããŸãããVisual Studioãéåžžã«åªãããµããŒããæäŸããŠããããã䜿çšããªãããšã¯çœªã§ãã
ãã®ãããªã¢ããªã±ãŒã·ã§ã³ããã°ããäœæããæ¹æ³ãç¥ã£ãŠããã°ããµãŒããŒãç¬èªã®Webãµã€ãã«ããéã«ãWebãã¯ãããžãŒïŒnpmãWebpackãTypeScriptèªäœãå«ãïŒãå®å šã«åŠç¿ã§ããŸãã
çŸæç¹ã§ã¯ãASP.NETã«ã¯Webpackã«ãããã®ãšåæ§ã®ã¡ã«ããºã ãæ¢ã«çµã¿èŸŒãŸããŠãããã¹ã¿ãžãªïŒAnyway 2017ïŒã¯TypeScriptã§åäœããTypeScriptã³ã³ãã€ã©ã®æ§æãã¡ã€ã«ãäœæãããšèªåçã«ã³ã³ãã€ã«ãããŸã- aã
ãã ããããããã¹ãŠã¯ãWebã³ãã¥ããã£ã§ã¯ãªããASP.NETéçºè
ã«ãã£ãŠãµããŒããããŠããŸãã
ãã®ãã¥ãŒããªã¢ã«ã®æšæºTypeScriptã³ã³ãã€ã©ã¯ç¡å¹ã«ãªã£ãŠãããnpmã®ã¢ãžã¥ãŒã«ã§ãããã®ã䜿çšãããŸãã
æºåãã
éå§ããããã«ããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããå¿ èŠããããã®
- Visual Studio 2017ã³ãã¥ãã㣠-ã³ã³ããŒãã³ããã€ã³ã¹ããŒã«ãããšããASP.NETããã³Coreã«é¢é£ãããã¹ãŠãéžæããŸã
- Node.jsãšnpm -Visual Studioã§ãããžã§ã¯ãããã«ããããšãã«npmãåäœããWebpackã¹ã¯ãªãããå®è¡ããã«ã¯Node.jsãå¿ èŠã§ãã node.jsã®ææ°ããŒãžã§ã³ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ãããšãnpmãã€ã³ã¹ããŒã«ãããŸãã
ãããžã§ã¯ãäœæ
Visual Studioãéããæšæºã®ASP.NET Core Webã¢ããªã±ãŒã·ã§ã³ïŒ.NET CoreïŒãã³ãã¬ãŒãã䜿çšããŠæ°ãããããžã§ã¯ããäœæããŸãã ãã³ãã¬ãŒãã¯Templates-Visual CïŒ-Webã«ãããŸã ã ãã®ãããªãã³ãã¬ãŒãããªãå Žåãäžéšã®ã³ã³ããŒãã³ããã€ã³ã¹ããŒã«ãããªãå¯èœæ§ããããŸãïŒVisual Studioã€ã³ã¹ããŒã©ãŒãå床å®è¡ããŠã€ã³ã¹ããŒã«ããå¿ èŠããããŸãïŒã
ããã§ãåæãããžã§ã¯ããã§ããŸãããã³ã³ãã€ã«ããŠå®è¡ããå¿ èŠããããŸãã
gitã䜿çšããå Žåã¯ãããã«.gitignoreãã¡ã€ã«ããœãªã¥ãŒã·ã§ã³ã®ãããã©ã«ããŒã«è¿œå ããŸãïŒããã§gitãªããžããªãŒãåæåããŸãïŒã Visual Studioã®ãœãªã¥ãŒã·ã§ã³ã®.gitignoreãã¡ã€ã«ã¯ãããããååŸã§ããŸã ã
å žåçãªãããžã§ã¯ããç°¡çŽ åãã
次ã«ããããžã§ã¯ããå¯èœãªéãã·ã³ãã«ã«ãªãããã«å€æŽããŸãã
Hello WorldãäœããŸãããã
次ã®ãã¡ã€ã«ãåé€ããŸã
- bower.json ïŒããã³ãã®äžã«ãã¹ãããã.bowerrc ïŒã bundleconfig.json
- wwwrootãã©ã«ããŒã®ãã¹ãŠã®ã³ã³ãã³ãã favicon.icoãæ®ãããšãã§ããŸãã
- Viewsãã©ã«ããŒ-Views / Home / Index.cshtmlãé€ããã¹ãŠã®å éšãåé€ããŸã
HomeController
ã¯ã©ã¹ã®Controllers / HomeController.csãã¡ã€ã«å
å
éšã次ã®ã³ãŒãã«çœ®ãæããŸã
public IActionResult Index() => View(); public string Error() => "Error";
å®éã Index()
ããã³Error()
ã¡ãœãã以å€ã¯ãã¹ãŠåé€ãããŸããã Error()
ã¯ãã¥ãŒã®ä»£ããã«æååãErrorããè¿ãããã«ãªããŸããïŒãã®ãã¥ãŒã§ãã¡ã€ã«ãåé€ããããïŒã
æåŸã®ä»äžã-Views / Home / Index.cshtmlãã¡ã€ã«ã®å 容ã次ã®ãã®ã«çœ®ãæããŸã
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Index</title> </head> <body> <h1>Hello world</h1> </body> </html>
ããã§ãåºæ¬çãªæ倧éåçŽåããããããžã§ã¯ããã§ããŸããã ã³ã³ãã€ã«ããŠå®è¡ã§ããŸããããã¹ããHello worldããããŒãžã«è¡šç€ºãããŸã
npmãè¿œå
package.jsonãã¡ã€ã«ããããžã§ã¯ãã«è¿œå ããŸã
{ "version": "1.0.0", "name": "yourappname", "private": true }
ãyourappnameãã®ä»£ããã«ããããžã§ã¯ãã®ååãå°æåã§å ¥åããŸãã
npmã¯npm-debug.logãšããååã§ãã°ã«æžã蟌ãããšãã§ããŸãã å¹²æžããªãããã«ããããžã§ã¯ãããé€å€ããå¿
èŠããããŸãã ããã¯ãã¹ã¿ãžãªã®ã³ã³ããã¹ãã¡ãã¥ãŒãåŒã³åºãã [ãããžã§ã¯ãããé€å€ ]ãéžæããããšã§å®è¡ã§ããŸãã ãŸãã¯ããŸã äœæãããŠããªãå ŽåïŒã»ãšãã©ã®å Žåããã該åœããŸãïŒã <Project>
ã«ãŒãã¿ã°ã«ä»¥äžãè¿œå ããããšã«ããããããžã§ã¯ãã®.csprojãã¡ã€ã«ãç·šéã§ããŸãã
<ItemGroup> <None Remove="npm-debug.log" /> </ItemGroup>
ããã§ãnpmããµããŒããããŸããããããžã§ã¯ãã®äŸåé¢ä¿ã§ãã¹ã¿ãžãªã¯ãnpmãããŒãã衚瀺ããŸãã
ãããžã§ã¯ãããã«ãããå ŽåïŒããã³ãããžã§ã¯ããéããšãã package.jsonãã¡ã€ã«ãå€æŽãããšããªã©ïŒãnpmäŸåé¢ä¿ãæå®ãããŠããå ŽåïŒçŸåšã¯ããã§ã¯ãããŸããïŒã埩å ããã»ã¹ãéå§ãããŸãã äŸåé¢ä¿ã¯ãããžã§ã¯ããã©ã«ããŒã®node_modulesãã©ã«ããŒã«ããŠã³ããŒããããŸãïŒStudioã¯ãã®ãã©ã«ããŒããããžã§ã¯ãã®äžéšãšããŠèªèããŸããïŒã
Webpackãè¿œå
Webpackã¯npmäŸåé¢ä¿ã§ããããã package.jsonã«äŸåé¢ä¿ãšããŠè¿œå ããå¿ èŠããããŸãã ã¯ã©ã€ã¢ã³ãåŽã®JavaScriptã³ãŒãã§ã¯äœ¿çšãããªãããã deväŸåé¢ä¿ãšããŠå®£èšãããŸãã ç§ãã¡ã«ãšã£ãŠãããã¯ãWebpackãçæããã³ã³ãã³ãïŒJavaScriptã³ãŒããå«ãïŒããµãŒããŒäžã§ãã¯ã©ã€ã¢ã³ãäžã§ãVisual Studioã®è¿œå ã³ã³ãã€ã«ããŒã«ãšããŠæ©èœããããšãæå³ããŸãã
Webpackèªäœã«å ããŠãç°¡åã«ãã2ã€ã®ãã®ãå¿ èŠã«ãªããŸãïŒãã ãããªãã·ã§ã³ã§ãïŒ
- Webpackããã¡ã€ã«ãäœæãããã©ã«ããŒãã¯ãªã¢ããWebpackã®ãã©ã°ã€ã³ïŒãã®ãã¥ãŒããªã¢ã«ã§ã¯ããã®ãã©ã«ããŒã¯wwwroot / bundleãšåŒã°ããŸãïŒã
- StudioããASP.NETã¢ããªã±ãŒã·ã§ã³ãèªåçã«ãã«ããããã³ã«Webpackãå®è¡ã§ããVisual Studioæ¡åŒµæ©èœã
ãŸããVisual Studioã®æ¡åŒµæ©èœãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããŸãããNPM Task Runnerããšããååã§èŠã€ãããããã®ãªã³ã¯ããããŠã³ããŒãã§ããŸãã
次ã®è¡ãpackage.jsonã«è¿œå ããŸãïŒäžæ¬åŒ§å ã«è¿œå ïŒ
"devDependencies": { "webpack": "^2.5.1", "clean-webpack-plugin": "^0.1.16" }, "scripts": { "webpack-script": "webpack" }, "-vs-binding": { "BeforeBuild": [ "webpack-script" ] }
"devDependencies"
ã§ã¯ãWebpackèªäœãšãã©ã°ã€ã³ãæå®ããŠãçæããããã®ãã¯ãªãŒã³ã¢ããããŸããã
"scripts"
ã§ã "webpack-script"
ãå®è¡ãã"webpack-script"
ãšããã¹ã¯ãªãããæå®ããŸããïŒãã®æç¹ã§ãã³ã³ãã³ãã®çæãã³ãŒãã®è»¢çœ®ãªã©ïŒã 以åã«ã€ã³ã¹ããŒã«ããVisual Studioæ¡åŒµæ©èœã«ããããã®ã¹ã¯ãªããã¯å®è¡å¯èœãªã¿ã¹ã¯ãšããŠã¹ã¿ãžãªã«è¡šç€ºããããããã¢ããªã±ãŒã·ã§ã³ã®æ§ç¯æã«ãã®ã¿ã¹ã¯ãå®è¡ããããã«ã¹ã±ãžã¥ãŒã«ã§ããŸãã
"-vs-binding"
ããããžã§ã¯ãããã«ãããåã«ãVisual Studioã"webpack-script"
ã¿ã¹ã¯ïŒã€ã³ã¹ããŒã«ãããæ¡åŒµæ©èœã«ããã¹ã¿ãžãªã«è¡šç€ºãããïŒã¿ã¹ã¯ãåŒã³åºãå¿
èŠãããããšã瀺ããŸããã
ããã§ãWebpackèªäœãæ§æããå¿
èŠããããŸãã webpack.config.js JavaScriptã¹ã¯ãªããã䜿çšããŠèšå®ãããŸãããã®ã¹ã¯ãªããã¯ã webpack-script
ã¿ã¹ã¯ãwebpack-script
ãšãã«node.jsãä»ããŠå®è¡ãwebpack-script
ãŸãã webpack.config.jsãã¡ã€ã«ããããžã§ã¯ãã«è¿œå ãããã®å
容ã次ã®ã³ãŒãã§åããŸã
"use strict" { // output let path = require('path'); // (bundle) const CleanWebpackPlugin = require('clean-webpack-plugin'); // const bundleFolder = "wwwroot/bundle/"; module.exports = { // entry: "./Scripts/main.js", // output: { filename: 'script.js', path: path.resolve(__dirname, bundleFolder) }, plugins: [ new CleanWebpackPlugin([bundleFolder]) ] }; }
ããã§ã¯ãJavaScriptãã¡ã€ã«ãžã®å ¥åãã¹ãšåºåãã¹ãèšå®ããåºåãã©ã«ããŒãã¯ãªãŒãã³ã°ããããã«ä»¥åã«è¿œå ãããã©ã°ã€ã³ãç»é²ããŸããã
webpackã¯ãå ¥åã«åºã¥ããŠåºåãã¡ã€ã«ãçæããŸãã å ¥åãã¡ã€ã«ã¯ãŸã ãªãã®ã§ãäœæããå¿ èŠããããŸãã 次ã®å 容ã§scripts / main.jsãã¡ã€ã«ãäœæããŸã
document.getElementById("helloworld").innerText = "Hello world from script";
å ¥åãã¡ã€ã«ã¯wwwrootã§ã¯ãªãScriptsãã©ã«ããŒã«ããããããŠãŒã¶ãŒã¯ã¢ã¯ã»ã¹ã§ããŸãããWebpackã«ãã£ãŠçæãããåºåãã¡ã€ã«ã¯wwwroot / bundle /ãã©ã«ããŒã«ç§»åããã¯ã©ã€ã¢ã³ããå©çšã§ããããã«ãªããŸãã
ã¯ã©ã€ã¢ã³ãåŽã§ã¯ãåºåãã¡ã€ã«ã¯ã/ bundle / script.jsã«ãããŸã ãããã§ã ãã¯Webã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠãããµã€ãã®ã¢ãã¬ã¹ã§ãã
Views / Home / Index.cshtmlãã¡ã€ã«ãå€æŽããŠãåºåãã¡ã€ã«ãå«ãŸããããã«ããã¹ã¯ãªãããããŒãžäžã®ããã¹ããïŒhelloworldèŠçŽ ã®idã«ãã£ãŠïŒå€æŽã§ããããã«ããŸãã
ãããè¡ãã«ã¯ã <body>
å
éšã次ã®ããã«çœ®ãæããŸã
<h1 id="helloworld"></h1> <script src="~/bundle/script.js"></script>
gitã䜿çšããå Žåã¯ãWebpackã«ãã£ãŠçæããããã¡ã€ã«ãé€å€ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãå¥ã®.gitignoreãã¡ã€ã«ãäœæããŸããããããžã§ã¯ããã©ã«ããŒã«é 眮ããŸãïŒãœãªã¥ãŒã·ã§ã³ãã©ã«ããŒãšæ··åããªãã§ãã ããïŒ
# webpack- wwwroot/bundle/
ãã®å Žåãã¹ã¿ãžãªã¯ãããžã§ã¯ãã®.gitignoreãã¡ã€ã«ã衚瀺ããããããããžã§ã¯ãã®.csprojãã¡ã€ã«ã§ã¯ãã«ãŒã<Project>
å
ã«æ¬¡ã®è¡ãè¿œå ããŸãïŒãŸãããŸãã¯ãã¡ã€ã«ã®ã³ã³ããã¹ãã¡ãã¥ãŒ-> ãããžã§ã¯ãããé€å€ ïŒã
<ItemGroup> <None Remove=".gitignore" /> </ItemGroup>
ããã§ããããžã§ã¯ãã¯npmãšWebpackã䜿çšããããã«å®å šã«æ§ââæãããŸããã ã¢ããªã±ãŒã·ã§ã³ãã³ã³ãã€ã«ããŠå®è¡ãããšããHello world from scriptããšããããã¹ããããŒãžã«è¡šç€ºãããŸã
ãã®æ®µéã§ã package.jsonã® "dependencies"
ã»ã¯ã·ã§ã³ã§å®£èšãã scripts / main.jsã§äœ¿çšããŠJavaScripté¢æ°ãã€ã³ã¹ããŒã«ãã require(" ")
é¢æ°require(" ")
ä»ããŠãããã®ã©ã€ãã©ãªãã¢ãžã¥ãŒã«ãšããŠæ¥ç¶ããŸãã ããšãã°ããã®æ¹æ³ã§jqueryã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããå Žåã Scripts / main.jsãã¡ã€ã«ã¯æ¬¡ã®ããã«æžãæããããšãã§ããŸãïŒæ³šïŒããã¯åãªãäŸã§ãããjqueryãã€ã³ã¹ããŒã«ãããmain.jsãå€æŽãããããå¿
èŠã¯ãããŸããïŒ
var $ = require('jquery'); $("#helloworld").text("Hello world");
å¯äžã®ããšã¯ãVisual Studioã®å ¥åãã¡ã€ã«ã®ãããã°ãæ©èœããªãããšã§ãã ãã ããããã¯TypeScriptãµããŒããè¿œå ããããšã§ä¿®æ£ã§ããŸãã
TypeScriptãè¿œå
ãŸããæšæºã®TypeScriptãã©ã³ã¹ãã¬ãŒã·ã§ã³ãç¡å¹ã«ããå¿
èŠããããŸãã ãããè¡ãã«ã¯ã .csprojãããžã§ã¯ããã¡ã€ã«ã®ã«ãŒã<Project>
ã¿ã°å
ã«æ¬¡ã®è¡ãè¿œå ããŸã
<PropertyGroup> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> </PropertyGroup>
次ã«ãnpmã®deväŸåé¢ä¿ãšããŠTypeScriptãè¿œå ããŸãã ãããè¡ãã«ã¯ã "devDependencies"
ã»ã¯ã·ã§ã³ã®package.jsonãã¡ã€ã«ã«æ¬¡ãè¿œå ããŸã
"typescript": "^2.3.2", "ts-loader": "^2.0.3"
次ã«ãTypeScriptã³ã³ãã€ã©ã®æ§æãã¡ã€ã«ãäœæããå¿ èŠããããŸãã 次ã®å 容ã§tsconfig.jsonãã¡ã€ã«ãäœæããŸã
{ "compilerOptions": { "noImplicitAny": false, "noEmitOnError": true, "removeComments": false, "alwaysStrict": true, "allowSyntheticDefaultImports": true, "lib": [ "dom", "es5", "es2015.promise" ], "allowJs": true, "target": "es5", "module": "es2015", "moduleResolution": "node", "sourceMap": true }, "include": [ "./Scripts/*" ], "compileOnSave": false }
ãã®ãã¡ã€ã«ã§æå®ãããããã€ãã®å€ã®èª¬æ
-
"allowJs": true
-JavaScriptããJavaScriptãžã®ç¿»èš³ãæå¹ã«ããŸãïŒæ°ããããŒãžã§ã³ã®èšèªããå€ãããŒãžã§ã³ãžããã¡ã€ã«æ¡åŒµå.jsïŒ -
"target": "es5"
ã¯ãTypeScriptãšå ¥åJavaScrptãå€æãããJavaScriptã®åºåããŒãžã§ã³ã§ã -
"module": "es2015"
-ã¢ãžã¥ãŒã«ãæäœããããã®æ§æ -
"moduleResolution": "node"
-ã¢ãžã¥ãŒã«ã解決ããããã®æŠç¥ã¯ãnode.jsãšåãã§ãã -
"sourceMap": true
-TypeScriptãããã°çšã®ããŒã¿çæã"sourceMap": true
ãŸã -
"include": [ "./Scripts/*" ]
-åºåJavaScriptã«ãã©ã³ã¹ããŒãºããå¿ èŠããã.tsããã³.jsã®ãœãŒã¹ãååŸããå Žæã瀺ããŸã
次ã«ãWebpackã§TypeScriptã®åéãäœãå¿ èŠããããŸãã ãããè¡ãã«ã¯ã Webpack.config.js Webpackãæ§æããããã®ã¹ã¯ãªãããã¡ã€ã«ã次ã®ããã«çœ®ãæããŸãïŒå®éãäžéšã®å Žæãå€æŽããŸããããã¹ãŠã®å€æŽãæžã蟌ãŸãªãããã«ãå®å šãªãã¡ã€ã«ãæçš¿ããŸãïŒ
"use strict" { // output let path = require('path'); // (bundle) const CleanWebpackPlugin = require('clean-webpack-plugin'); // const bundleFolder = "wwwroot/bundle/"; module.exports = { // entry: "./Scripts/main.ts", // output: { filename: 'script.js', path: path.resolve(__dirname, bundleFolder) }, module: { rules: [ { test: /\.tsx?$/, loader: "ts-loader", exclude: /node_modules/, }, ] }, resolve: { extensions: [".tsx", ".ts", ".js"] }, plugins: [ new CleanWebpackPlugin([bundleFolder]) ], // // ( ) devtool: "inline-source-map" }; }
ããã§ã¯ãå
¥åã¹ã¯ãªããã®æ¡åŒµåã.jsãã.tsã«å€æŽããå
¥åã¹ã¯ãªãããTypeScript loader: "ts-loader"
ïŒ loader: "ts-loader"
ïŒãä»ããŠæž¡ãããããšã瀺ããä»ã®ããã€ãã®ããšãè¡ããŸããã
æåŸã®ã¹ãããã¯ãå ¥åã¹ã¯ãªãããã¡ã€ã«ã®ååãScripts / main.jsããScripts / main.tsã«å€æŽããããšã§ããå éšã¯åããŸãŸã«ããŠããããšãã§ããŸãã
ãŸãšã
ããã ãã§ãïŒ ããã§ãnpmãWebpackãTypeScriptãåããASP.NET Coreã§åäœãããããžã§ã¯ããã§ããŸããããããã¯ãã¹ãŠ1ã€ã®ãã³ãã«ã§åäœããŸãã
TypeScriptãããã°ã¯Visual Studioãããå©çšã§ããããã«ãªããŸãããå ¥å.tsãã¡ã€ã«ã«ãã¬ãŒã¯ãã€ã³ããèšå®ãããããã°ã¢ãŒãã§ãããžã§ã¯ããéå§ã§ããŸãïŒã¯ãã ãŸãã¯ã€ã³ã¿ãŒããããšã¯ã¹ãããŒã©ãŒãã©ãŠã¶ãŒã§å®è¡ããå¿ èŠããããŸããããããªããšããããã°ã¯æ©èœããŸãããããŒãžãããŒãããåŸã«ããŒãžã®æŽæ°ãæ瀺çã«æŒããå Žåã«ã®ã¿ãæããã«ãããã¬ã¯ããã«ã¯ãã ã«æ¥ç¶ããŸããïŒã åæã«ããã¬ãŒã¯ãã€ã³ãã¯å ¥åãã¡ã€ã«ã«èšå®ãããŸãããã³ãŒãã¯å®éã«ã¯åºåãšããŠæ©èœããŸãïŒåºåã³ãŒãã§ã¯ãwebpackã¯åºåããå ¥åãã¡ã€ã«ãžã®ãããã³ã°ã«å¿ èŠãªæ å ±ãã³ã¡ã³ããšããŠæžã蟌ã¿ãŸãïŒã
Scriptsãã©ã«ããŒã«ä»ã®å
¥åãã¡ã€ã«ã.tsãŸãã¯.jsãšããŠäœæã§ããäž¡æ¹ãæ°ããEcmaScriptæšæºãå®å
šã«ãµããŒãããŸãïŒåºåãã¡ã€ã«ã¯es5æšæºã«ãªããŸãïŒã è¿œå ã®å
¥åãã¡ã€ã«ãæ¥ç¶ããã«ã¯ãã¢ãžã¥ãŒã«åœ¢åŒã§ãã©ãŒããããã import
ã¹ããŒãã¡ã³ããŸãã¯require()
é¢æ°ãä»ããŠmain.tsã«æ¥ç¶ããrequire()
ãŸãã
å¥ã®å°ããªã³ã¡ã³ã-åºåãã¡ã€ã«ïŒ wwwroot / bundle / folderã«ãããã®ïŒã¯ã .csprojãã¡ã€ã«ãä»ããŠãããžã§ã¯ãããé€å€ããªãæ¹ãè¯ãã§ããã¹ã¿ãžãªããããã衚瀺ããªãå Žåãå ¥åãã¡ã€ã«ã®ãããã°ãæ©èœããªããªãããã§ãã