UWP ã¢ããªéçºã« TypeScript + React ãå°å ¥ãããã¨ã®æ¤è¨ (Node.MSBuild.Npm ã®ç´¹ä»)
ããã«ã¡ã¯ï¼ æ ªå¼ä¼ç¤¾ã¯ã¦ãªã«ã¦ã主㫠ãã¯ã¦ãªããã¯ãã¼ã¯ã Android ã¢ããªã®éçºãè¡ã£ã¦ãã id:nobuoka ã§ãã ãã®è¨äºã¯ããã¯ã¦ãªãããããã¼ã¢ããã³ãã«ã¬ã³ãã¼ 2015ã ã® 14 æ¥ç®ã®è¨äºã§ãã æ¨æ¥ã¯ id:hatz48 ã«ãã ãTypeScript だけで Web アプリケーションを作るã ã§ããã
ä»æ¥ã¯ãæ¨æ¥ã«å¼ãç¶ã TypeScript ã®è©±é¡ã¨ãªãã¾ãã 主ã«ã¯ã©ã¤ã¢ã³ããµã¤ã (ç¹ã« UWP ã¢ããª) ã§ã® TypeScript 㨠React ã®çµã¿åããã«ã¤ãã¦æ¤è¨ãããã¨æãã¾ãã
(ãã®è¨äºã®å 容ã¯ãUWP ã¢ããªã¸ã®å°å ¥ãç®çã¨ããã¨ãã® TypeScript + React ã®ç°å¢ã®ä¸ä¾ã§ããããã¹ããã©ã¯ãã£ã¹ã§ã¯ããã¾ããã ããè¯ãæ¹æ³ãªã©ãããã¾ãããæãã¦ãã ããã¾ãã)
UWP ã¢ããªã¨ TypeScript + React
UWP ã¢ããªã¨ã¯ ãUniversal Windows Platform ã¢ããªã ã®ãã¨ã§ãWindows 10 ã§å°å ¥ããã Windows ãã©ãããã©ã¼ã åãã®ã¢ããªã®ä¸ç¨®ã§ãã Windows 8 ã§å°å ¥ããã Windows ã¹ãã¢ã¢ããªã Windows Phone 8.1 åãã® Windows Phone ã¢ããªã®é²åçã¨ããæãã§ããã
ç¾å¨ã®ã¨ããæ ªå¼ä¼ç¤¾ã¯ã¦ãªã§ã¯ UWP ã¢ããªã®éçºã¯è¡ã£ã¦ãã¾ããããWindows ã¹ãã¢ã¢ã㪠ãã¯ã¦ãªããã¯ãã¼ã¯ã ã 2012 å¹´ã«ãªãªã¼ã¹ãã¦ãã¾ãã *1
JS ãå¿«é©ã«æ¸ã : TypeScript ã®å°å ¥
Windows ã¹ãã¢ã¢ããªã Windows Phone ã¢ããªã¨åæ§ã«ãUWP ã¢ããªã JS + HTML + CSS ã§éçºãããã¨ãã§ãã¾ãã Windows ã¹ãã¢ã¢ã㪠ãã¯ã¦ãªããã¯ãã¼ã¯ã ã JS + HTML + CSS ã®çµã¿åããã§æ¸ããã¦ãã¾ãã
JS 㯠Web éçºè ã«ã¨ã£ã¦é¦´æã¿ã®ããè¨èªã§ãã®ã§ãã¢ããªéçºã«åãæãããããã¨ããã®ã¯å©ç¹ã§ããã ä¸æ¹ã§ãç´ ã® JS ã«ã¯å¤æ°ã«åããªããããªãã¡ã¯ã¿ãªã³ã°ãªã©ããã¥ããã¨ããé£ãããã¾ã *2ã ããã解決ããããããããã Alt JS ã使ç¨ãããã¨ãæ¤è¨ãããã¨æãã¾ãããUWP ã¢ããªéçºã§ä½¿ç¨ããã®ã§ããã°ã¾ã TypeScript ãåè£ã«ãããã§ãããã UWP ã¢ããªéçºã«ä½¿ç¨ãããçµ±åéçºç°å¢ (IDE) Visual Studio 2015 ã§ã¯æ¨æºã§ TypeScript ããµãã¼ãããã¦ãããããUWP ã¢ããªã®ããã¸ã§ã¯ãã«å®¹æã« TypeScript ãå°å ¥ã§ãã¾ãã Microsoft ã TypeScript ã®ãªãªã¼ã¹ãè¡ã£ã¦ãããããã TypeScript å°å ¥ã«ããã£ã¦ã®å®å¿æã«ã¤ãªãã£ã¦ãã¾ãã ãã»ã© TypeScript ã¨æ¯ã¹ã¦æå©ãªè¨èªãããã°ããã使ãã¨ããããããã¾ããããç§èªèº«ã¯ç¾ç¶ã§ã¯ TypeScript ã使ãã®ãä¸çªã ã¨èãã¦ãã¾ãã
å®éã« ãã¯ã¦ãªããã¯ãã¼ã¯ã Windows ã¹ãã¢ã¢ã㪠*3 ã§ã TypeScript ãå°å ¥ãã¦éçºãã¦ãããç´ ã® JS ã使ãã®ã«æ¯ã¹ã¦æ¥½ã«éçºãé²ãããã¨ãã§ãã¦ãã¾ãã
View ã®å¦çãå¿«é©ã«ããããã« : React ã®å°å ¥ãæ¤è¨
TypeScript ãå°å ¥ãããã¨ã§ JS ã®å¤æ°ã«åä»ããè¡ãã㦠IDE ã®ãµãã¼ããåãããããªããJS ã®ä¸çã«ã¤ãã¦ã¯å¿«é©ã«ãªãã¾ãã ããããªãã TypeScript ãå°å ¥ããã ãã§ã¯ view æä½ (ãä½ããã®ãã¼ã¿ãç»é¢ã«è¡¨ç¤ºããã ã¨ããå¦ç) ã®é¨åã¯ãã¾ãæ¹åããã¾ããã UWP ã¢ããªéçºã®ããã® JS ã®ã©ã¤ãã©ãªã¨ã㦠WinJS ã¨ãããã®ããããç»é¢ã«ãã¼ã¿ã表示ããããã®ãã³ãã¬ã¼ãã»ãã¤ã³ãã£ã³ã°ã®æ©è½ãæä¾ããã¦ããã®ã§ãããããããªããªãç´ æ´ãªä»æ§ã§ãåã®æ©æµãåãã¥ããããã§ãã
ãã¯ã¦ãªããã¯ãã¼ã¯ã Windows ã¹ãã¢ã¢ããªã®éçºã§ãããã¯ã View ãæ±ãé¨åããããã«æ¸ãããããããæ¹æ³ãåãå ¥ãããã¨èãã¦ãã¾ãã
ããã§ãä½ããã®ã©ã¤ãã©ãªãå°å ¥ãããã¨ãæ¤è¨ãã¾ããã åè£ã¨ãã¦ã¯ã以ä¸ã®ãã®ãèãã¾ããã ãããã JS çéã§è©±é¡ã«ãªããããã©ã¤ãã©ãªã§ããã
- React
- JSX æ§æã使ã£ã¦ JS å´ã« HTML æ§é ãè¨è¿°ããã
- TypeScript ã¨ã®ç¸æ§ãè¯ãã
- ã¢ããªéçºãããããã§æ±ãããããã
- Polymer
- æ¨æºã® Web Components ãæèãã¦éçºããã¦ãããå°æ¥æ§ã¯ããããã«è¦ããã
- ç¬èªã® HTML ã¿ã°ãå®ç¾©ã㦠HTML å´ã§ä½¿ç¨ã§ããã®ã§ã(React ã¨æ¯ã¹ã¦) ãµã¼ãã¼ãµã¤ã㧠HTML ãçæãããããªå ´é¢ã§æ±ãããããã
- TypeScript ã¨ã®ç¸æ§ã¯ä¸æã
- AngularJS
- ç¾å¨ Angular 2 ãéçºããã¦ããããã¼ã¸ã§ã³ 1 㨠2 ã®äºææ§ããªããªããããªãã¨ãããç¾å¨ Angular ãå°å ¥ããã®ã¯ãªã¹ãã¼ã ã¨èããããã
- View é¨åãæ軽ã«æ±ãããã ãã«å°å ¥ããã«ã¯è¦æ¨¡ã大ããããã«æããã
å ¨é¨è©¦ãã¦ã¿ã¦ã©ããè¯ããè©ä¾¡ã§ããã°ããã£ãã®ã§ãããã¾ã㯠TypeScript ã¨ç¸æ§ããããã¢ããªéçºã§æ±ããããã㪠React ã ãã試ãã¦ã¿ã¾ããã
TypeScript 㨠React (JSX) ã®ç¸æ§
React ã§ã¯ JSX æ§æ (JSX syntax) ãç¨ã㦠JS ã®ä¸ã« DOM æ§é ãè¨è¿°ãã¾ãã ããã¦ãTypeScript ã§ã¯ JSX æ§æããµãã¼ãããã¦ãã¾ãã
JSX æ§æã§ã®åãã§ãã¯ãªã©ããµãã¼ãããã¦ããã®ã§ãReact ã使ããã¨ã§ View ã®å¦çã®é¨åã§ã IDE ã®ãµãã¼ããåãããããããªãã¾ãã ãã©ã°ã¤ã³ãªã©ã§ã¯ãªããTypeScript ã®å¦ç系㫠JSX æ§æã®å¦çãçµã¿è¾¼ã¾ãã¦ããã®ã§ãTypeScript 㨠JSX ã®ç¸æ§ã¯é常ã«è¯ãã¨ããã¾ãã
TypeScript + React ã®ç°å¢
ãã¦ãããããã¯å®éã« TypeScript + React ã UWP ã¢ããªéçºã§ç¨ããããã®ç°å¢ã«ã¤ãã¦èãã¾ãã UWP ã¢ããªã¯ããã¼ã«ã«ãã¡ã¤ã«ä¸ã® HTML + JS + CSS ããã©ã¦ã¶ä¸ã«è¡¨ç¤ºããã®ã¨ä¼¼ããããªä»çµã¿ã§åãã¾ãã®ã§ãã¾ãã¯ãã¼ã«ã«ãã¡ã¤ã«ã·ã¹ãã ä¸ã§ãã«ããã¦ãã©ã¦ã¶ä¸ã«è¡¨ç¤ºã§ããããã«ããç°å¢ãèãã¾ãã
TypeScript + React ã®ç°å¢ãæ´ããããã«ã¯ãnpm ã使ç¨ããã®ãç°¡åã§ãããã
- TypeScript ã®ãã«ã : npm ã® typescript ã¢ã¸ã¥ã¼ã«
- React ã®ã½ã¼ã¹ã³ã¼ã : npm ã® react ã¢ã¸ã¥ã¼ã«
- React ã®åå®ç¾© : npm ã® dtsm ã¢ã¸ã¥ã¼ã«ã使ç¨ã㦠DefinitelyTyped ãã react.d.ts ãåå¾
React ã使ãã«ããã£ã¦ã¯ CommonJS ã¢ã¸ã¥ã¼ã«ã·ã¹ãã ã使ããã¨ãæ¨å¥¨ããã¦ãã¾ãã®ã§ãTypeScript ãè¨è¿°ããéã¯ã¢ã¸ã¥ã¼ã«å½¢å¼ã§è¨è¿°ããCommonJS å½¢å¼ã§ã³ã³ãã¤ã«ããããã«ãã¾ããã
We recommend using React with a CommonJS module system like browserify or webpack. Use the react and react-dom npm packages.
Getting Started | React
ã³ã³ãã¤ã«ãã JS ããã©ã¦ã¶ä¸ã§å®è¡ããããã«ãã¾ããUWP ã¢ããªã® JS ãã¡ã¤ã«ã¨ãã¦ä½¿ç¨ããããã«ã¯ãwebpack ã Browerify ãªã©ã使ç¨ãã¦ããã¯ãã¦ããå¿ è¦ãããã¾ãã ä»åã¯ç§ã¯ webpack ã使ç¨ãã¦ã¿ã¾ããã (webpack ãé¸æããçç±ã¯ç¹ã«ããã¾ããã ååããã¯ããwebpack ã¯å¤§è¦å·¨ç ²ã¨ããæããªã®ã§ãBrowserify ã§äºè¶³ãããªã Browserify ã§è¯ãããã ã¨ããæè¦ããããã¾ããã)
ãããã®ãã¼ã«ã使ç¨ã㦠TypeScript + React ã®ãã«ããè¡ãããã«ãããµã³ãã«ããã¸ã§ã¯ãã GitHub ã§å ¬éãã¦ãã¾ãã (ããã§ã¯ãã«ãã·ã¹ãã ã¨ã㦠Gradle ã使ç¨ãã¦ãã¾ãã)
UWP ã¢ããªã®ããã¸ã§ã¯ãã¸ã® TypeScript + React éçºç°å¢ã®å°å ¥ : Node.MSBuild.Npm ã®ç´¹ä»
ãã¦ãæå¾ã« UWP ã¢ããªã®ããã¸ã§ã¯ãã«ä¸è¿°ã®ç°å¢ãæ§ç¯ãããã¨ãèãã¾ãããã
ä¸ã§ç´¹ä»ãã Gradle ã使ã£ãããã¸ã§ã¯ãã§ã¯ãGradle ãã Node.js 㨠npm ã使ç¨ããããã« Gradle Plugin for Node ã使ç¨ãã¦ãã¾ãã ãã®ãã©ã°ã¤ã³ã¯ããã«ãæã« Node.js 㨠npm ããã¦ã³ãã¼ããã¦ãã¦ãã»ããã¢ãããã¦ãããã¨ãããã®ã§ãã
ä¸è¬ç㪠UWP ã¢ããªã®ããã¸ã§ã¯ãã®ãã«ãã·ã¹ãã ã§ãã MSBuild ã§ãåæ§ã®æ©è½ã使ããã°ãä¸ã§ç´¹ä»ããããã¸ã§ã¯ãã® Gradle é¨åã MSBuild ã«ç½®ãæãããã¨ã§ãUWP ã¢ããªã®ããã¸ã§ã¯ãã« TypeScript + React ã®éçºç°å¢ãå°å ¥ã§ããã§ãããã
MSBuild ã«ä¼¼ããããªæ©è½ãæä¾ãã NuGet ããã±ã¼ã¸ããªããã©ããæ¢ããã®ã§ãããNuGet ããã±ã¼ã¸ã®ä¸ã« node.exe ã npm ã®å種ãã¡ã¤ã«ãå«ããããªãã®ã¯è¦ã¤ãããããã®ã®ããã«ãæã«ã»ããã¢ããããã¿ã¤ãã®ãã®ã¯ãªãããã§ãã *4ã ããã§ããã®ãããªæ©è½ãæ㤠Node.MSBuild.Npm ã¨ãã NuGet ããã±ã¼ã¸ãä½æããå ¬éãã¾ããã
使ç¨æ¹æ³ã¯ç°¡åã§ãã ã¾ããVisual Studio 㧠NuGet ããã±ã¼ã¸ããã¼ã¸ã£ãèµ·åã㦠ãNode.MSBuild.Npmã ãæ¤ç´¢ãã¦ã¤ã³ã¹ãã¼ã«ãã¦ãã ããã ãã¨ã¯ package.json ãè¨è¿°ãã¦ããã«ãæã«å®è¡ãããå¦çã build
ã¹ã¯ãªããã¨ã㦠package.json ã«å®ç¾©ããã ãã§ãã
ä¾ãã°ãTypeScript + React ç°å¢ãæ§ç¯ãã¦ãã«ãæã« TypeScript ã®ãã«ãã webpack ã«ããå¤æãå®è¡ããã«ã¯ã以ä¸ã®ããã«è¨è¿°ãã¾ãã
{ "name": "my-app", "private": true, "devDependencies": { "react": "^0.13.3", "webpack": "^1.12.9", "typescript": "^1.7.3", "dtsm": "^0.13.0" }, "scripts": { "build": "dtsm install & tsc -p ts --outDir built\\typescript & webpack" }, // ä¸é¨ç¥ }
ãã«ãæã«å®è¡ãããå¦çã®è¨è¿°æ¹æ³ã«é¢ãã¦ã¯ãããå°ãæ±ããããããã«ã§ããã¨è¯ããªãã¨æã£ã¦ãã¾ãã
ãã²ãå©ç¨ãã ããã
TypeScript + React ç°å¢ã«å¯¾ããè©ä¾¡
ã¾ã 軽ã試ãã¦ãã段éã§ãããç¾æç¹ã§ã®è©ä¾¡ã¯ä»¥ä¸ã®ãããªæãã§ãå人çã«ã¯ä»ã®ã©ã¤ãã©ãª (Polymer ã AngularJS) ã試ãã¾ã§ããªã UWP ã¢ããªéçºã«å°å ¥ãã¦è¯ãããã¨ããæ°ããã¦ãã¾ãã
- (è¯ã) TypeScript ã JSX ããµãã¼ããã¦ããã®ã§ãJSX æ§æå
ã§ã IDE ã®ãµãã¼ããåããããã¦è¨è¿°ããããã
- ããã¯æ¬å½ã«ä¾¿å©ã§ãã
- (è¯ã) React èªä½ã¯å¤§ããªãã¬ã¼ã ã¯ã¼ã¯ã§ã¯ãªããå°å
¥ãããããã
- ç»é¢å ã®ä¸é¨ã® DOM æ§é ã®æ§ç¯ã®ã¿ã« React ã使ç¨ãããªã©ã
- (è¯ã) React ã«ãã View ã®ã³ã³ãã¼ãã³ãåãã§ããéçºãããããªãã
- (è¯ã) WinJS å´ã§ React ç¨ã®ã¢ããã¿ãç¨æããã¦ãããWinJS ã¨ä¸ç·ã«ä½¿ããããã
- (å¾®å¦) TypeScript + React ã®ç°å¢ãä½ãã®ãå°ãé¢åã æ
£ããã°åé¡ã¯ãªãããã
- TypeScript ãã¢ã¸ã¥ã¼ã«ã¨ãã¦è¨è¿°ãããã©ããããã¢ã¸ã¥ã¼ã«ã¨ãã¦è¨è¿°ããå ´åã«ã¯ browserify ã使ãã webpack ã使ãããã¨ãã£ããã¨ã§æ©ã¿ããã§ãã (React 㯠CommonJS ã®ã¢ã¸ã¥ã¼ã«ã·ã¹ãã ã使ç¨ãããã¨ãæ¨å¥¨ãã¦ããã)
- (ä¸æãåé¡ãªããã) å°æ¥ã«ããã£ã¦ã¡ã³ããã³ã¹ãããããã©ããã
- Facebook ã«ãããªãªã¼ã¹ããã¦ããã®ã§ãã©ã¤ãã©ãªã®ã¡ã³ããã³ã¹ã®å¿é ã¯ããã»ã©ãªãããã
- 使ãæ¹æ¬¡ç¬¬ã§ã¯ããããReact ã使ããªããå¾ã ã«å¥ã®ã©ã¤ãã©ãªã«ç§»è¡ããã¨ããã®ãé£ããã¯ãªãããã
ãã¯ã¦ãªããã¯ãã¼ã¯ã ã® Windows ã¹ãã¢ã¢ããªãæ´æ°ããéã«ã¯ããããã£ãæè¡ãå°å
¥ãããã¨ã§ããéçºãããããã¡ã³ããã³ã¹ããããã³ã¼ããæ¸ããããã«ãªãããã§ãã *5
ãããã«
ã¯ã¦ãªã§ã¯ãããéçºãããããããã¡ã³ããã³ã¹ããããã³ã¼ããè¨è¿°ãã¦ãããã¨ããã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãï¼
ææ¥ã® ãã¯ã¦ãªãããããã¼ã¢ããã³ãã«ã¬ã³ãã¼ 2015ã ã®æ å½ã¯ id:motemen ã§ãã ã楽ãã¿ã«ï¼
*1:ä»¥ä¸ UWP ã¢ããªåãã®è©±ããã¾ãããWindows ã¹ãã¢ã¢ããªã§ãåºæ¬çã«åæ§ã§ãã
*2:UWP ã¢ããªã«éãã
*3:UWP ã¢ããªã§ã¯ãªãã§ããã大ä½ä¸ç·ã§ãã
*4:NuGet ããã±ã¼ã¸å ã« node.exe ã npm ãå«ããããªã¿ã¤ãã§ãæªãã¯ãªãã®ã§ãããexe ãã¡ã¤ã«ãè¤æ°ããã¸ã§ã¯ãã§å ±æãããã£ãããããã¸ã§ã¯ãã®é層ãæ·±ãå ´æã«ãã㨠npm ã®ããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ã«å¤±æããã¨ããåé¡ããã£ããããã®ã§ããã«ãæã«ãã¼ã ãã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ãã¦ãããã¿ã¤ãã®ãã®ã欲ããã®ã§ããã
*5:ãã®æ㯠ãã¯ã¦ãªããã¯ãã¼ã¯ã Windows ã¹ãã¢ã¢ããªã®å¤§å¹ ãªæ´æ°ãäºåãããã®ã§ã¯ããã¾ããã