node.js - Getting simple web project running with Fabric React -
----update----
got work using following:
- webpack
- typescript
- ts-loader
- react
- react-dom
- @types/react
- @types/react-dom
- office-ui-fabric-react
once had simple react example running, easy same fabric-react.
some tutorials:
- https://www.typescriptlang.org/docs/handbook/react-&-webpack.html
- https://medium.com/@gmonne/simple-app-layout-with-office-ui-fabric-react-2eac6361e1b4
----original post----
as newcomer react / node want create test application in visual studio 2017 using fabric react (fabric since want adopt office , feel). i've spent countless of hours figuring out how work, , encountering problem after problem (e.g. creating package.json, installing gulp, etc.) there many tutorials on topic of them seem bit scattered or on 1 of dependencies.
to start with:
- i want build web application - simple / basic, test purposes, , use of fabric ui components.
- i creating web project in visual studio 2017 asp.net core web application (.net core)
- my visual studio 2017 version is: community 2017, version 15.2 (26430.13)
- using fabric-react (and not fabricjs)
- using gulp suggested @ http://dev.office.com/fabric#/get-started
up till have used following documentation:
- https://dev.office.com/fabric#react
- http://dev.office.com/fabric#overview
- https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md
- http://leruplund.dk/2017/04/15/setting-up-asp-net-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-i/
- what correct way set gulp in visual studio 2017?
- https://travismaynard.com/writing/getting-started-with-gulp
and more forgot..
the steps done:
- installed
node(v6.11.2) - created web project called test2
- added
npm(v3.10.10) project using nuget package installer - created
package.jsonfile. not sure anymore, after 100 tests, if did manually usingnpm initor done automatically installing npm in project, anyway in project:
- installed
gulp(using link what correct way set gulp in visual studio 2017?), short summary, converted bundleconfig.json file gulp using bundler & minifier extension. - tested if
gulpran (and updating package.json) usingtask runner explorer(worked):
- installed office-ui-fabric-react explained here (https://dev.office.com/fabric#react), installed react , react-dom explained here (http://dattabase.com/sharepoint-app-fabric-ui-react-part-1-3/)
- added bunch of code
site.jsfile (which linked in mvc view) - added command bar react-fabric code listed here: http://dev.office.com/fabric#variants
this part getting stuck. firstly not sure, being unfamiliar react in general, if should add components view. secondly, not work , give me following error:
site.js:5 uncaught syntaxerror: unexpected token import anyone know on step went wrong? addition info: package.json contains:
{ "name": "test2", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "isc", "devdependencies": { "del": "^3.0.0", "gulp": "^3.9.1", "gulp-concat": "^2.6.1", "gulp-cssmin": "^0.2.0", "gulp-htmlmin": "^3.0.0", "gulp-uglify": "^3.0.0", "merge-stream": "^1.0.1" }, "dependencies": { "office-ui-fabric-react": "^4.34.0", "react": "^15.6.1", "react-dom": "^15.6.1" } } site.js contains:
import * react 'react'; import { assign } 'office-ui-fabric-react/lib/utilities'; import { commandbar } 'office-ui-fabric-react/lib/commandbar'; import { toggle } 'office-ui-fabric-react/lib/toggle'; export class commandbarbasicexample extends react.component<any, any> { constructor(props: any) { super(props); this.state = { issearchboxvisible: true, arenamesvisible: true, areiconsvisible: true }; } public render() { let { items, overflowitems, faritems } = this.props; let { issearchboxvisible: searchboxvisible, areiconsvisible: iconsvisible, arenamesvisible: namesvisible } = this.state; let filtereditems = items.map((item: any) => assign({}, item, { name: namesvisible ? item.name : '', icon: iconsvisible ? item.icon : '' })); let filteredoverflowitems = overflowitems.map((item: any) => assign({}, item, { name: namesvisible ? item.name : '', icon: iconsvisible ? item.icon : '' })); let filteredfaritems = faritems.map((item: any) => assign({}, item, { name: namesvisible ? item.name : '', icon: iconsvisible ? item.icon : '' })); return ( <div> <toggle label='show search box' checked={searchboxvisible} onchanged={issearchboxvisible => this.setstate({ issearchboxvisible })} ontext='visible' offtext='hidden' /> <toggle label='show names' checked={namesvisible} onchanged={arenamesvisible => this.setstate({ arenamesvisible })} ontext='visible' offtext='hidden' /> <toggle label='show icons' checked={iconsvisible} onchanged={areiconsvisible => this.setstate({ areiconsvisible })} ontext='visible' offtext='hidden' /> <commandbar issearchboxvisible={searchboxvisible} searchplaceholdertext='search...' elipisisarialabel='more options' items={filtereditems} overflowitems={filteredoverflowitems} faritems={filteredfaritems} /> </div> ); } } my project overview:
the example you're trying run, given in typescript, seem running node (javascript) application.
typescript should installed globally (npm install typescript -g). can compile .ts or .tsx command-line typing tsc site.tsx. note filetype should tsx file containing jsx template, , should .ts file containing regular typescript.
my advice follow this excellent example on how create new react application typescript using webpack. it's nice familiarize gulp task-runner, gulp no means necessary react development.
once have example , running, can include office-ui-fabric-react , create applications components.


Comments
Post a Comment