chris o'brien - introduction to the sharepoint framework for developers

34
Introduction to the SharePoint Framework (SPFx) Chris O’Brien - MVP

Upload: chris-obrien

Post on 16-Apr-2017

17.701 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: Chris O'Brien - Introduction to the SharePoint Framework for developers

Introduction to the SharePoint Framework (SPFx)Chris O’Brien - MVP

Page 2: Chris O'Brien - Introduction to the SharePoint Framework for developers

About me

Independent ConsultantHead of Development, Content and Code (UK)

www.sharepointnutsandbolts.com@ChrisO_Brien http://cob-sp.com/COBLinkedIn

Page 3: Chris O'Brien - Introduction to the SharePoint Framework for developers

SharePoint dev – state of the nationSubtle shift to client side developmentContent Editor/Script Editor web part + JavaScript – common approachEven on-premises projects using cloud-friendly techniques

Beyond jQuery - developers seeking to use latest techApps/add-ins – Angular, KnockoutRendering – React, HandlebarsCSS – LESS, SASSBuild – Gulp

Still difficult for devs new to SharePoint

Page 4: Chris O'Brien - Introduction to the SharePoint Framework for developers

What is the SharePoint Framework?

Modern pages and client web

parts

Client side applications (list-based and page-

based)

A new developmen

t model

New deployment possibilities

We’ll focus on these aspects

Page 5: Chris O'Brien - Introduction to the SharePoint Framework for developers

New “modern” pagesApps, but no IFrames!

Similar to recent Delve blog pages

New page “canvas” – no classic web part zones

Page 6: Chris O'Brien - Introduction to the SharePoint Framework for developers

Client web partsPure JavaScript implementation

“Baked-in JS injection”

Simplified end-user experience (e.g. web part properties)

Page 7: Chris O'Brien - Introduction to the SharePoint Framework for developers

Page types/web part types crossoverClassic pages Modern pages

Classic web parts Y NModern web parts

Y Y

Modern web parts can work in:- modern pages (of course)- classic pages

But classic web parts can NOT work in modern pages

Page 8: Chris O'Brien - Introduction to the SharePoint Framework for developers

A new era for SharePoint developersNot just JavaScript, but TypeScript!Use your preferred JS framework – React, Angular, Knockout, jQuery, or noneGulp for buildYeoman for startupNo need for Visual Studio!

Page 9: Chris O'Brien - Introduction to the SharePoint Framework for developers

Getting started with development

Page 10: Chris O'Brien - Introduction to the SharePoint Framework for developers

Starting a new solutionPre-requisites:Node.js, Yeoman Generator, TypeScript, GulpYeoman Generator for SPFx – “yo @microsoft/sharepoint”

Process:Create a folderUse Yo to get starter files

Page 11: Chris O'Brien - Introduction to the SharePoint Framework for developers

DemoStarting a SharePoint Framework solution

Page 12: Chris O'Brien - Introduction to the SharePoint Framework for developers

Writing code in SPFxFundamentalsCode is written in the “src” directory

TypeScript is expected (at least, for now) Compile-time checking – find bugs faster!A superset of JavaScript - not just ‘var’, but strings and numbers

Client web partsThe “render” method is top of the chain

Page 13: Chris O'Brien - Introduction to the SharePoint Framework for developers

TypeScript – top 3 things to know1. Variables and typesVariable types must be declared e.g. var foo: string or var foo: UserProfile var foo: any is the escape route – “I don’t need type-checking”

2. Typings for libraries (e.g. jQuery, CSOM)Typings provide code auto-completion - usually in a d.ts fileMost common libs have typings – add with TypeScript Definition Manager

3. Import a module to use itLike a “using” statement – but also ensures the module is loaded

Page 14: Chris O'Brien - Introduction to the SharePoint Framework for developers

Client web parts – diving deeperBaseClientSideWebPart provides:

DisplayModeContextDOMElementProperties/Render() etc.

Page 15: Chris O'Brien - Introduction to the SharePoint Framework for developers

Understanding the folder structureFolder Purpose

config Settings for bundling/deployment

dist Run-time files for your applib Intermediate folder in build

systemnode_modules JS dependencies

src Where you write codetypings TypeScript typings

See cob-sp.com/SPX-Files for more info

Page 16: Chris O'Brien - Introduction to the SharePoint Framework for developers
Page 17: Chris O'Brien - Introduction to the SharePoint Framework for developers

DemoCoding in the SharePoint Framework

Page 18: Chris O'Brien - Introduction to the SharePoint Framework for developers

Showed: Live reload

facility (using Gulp Watch)

Adding libs such as jQuery (e.g. typings)

Coding against SharePoint API

Demo explanation - 1

Page 19: Chris O'Brien - Introduction to the SharePoint Framework for developers

Showed: Code running in

local ‘workbench’ host

Demo explanation - 2

Page 20: Chris O'Brien - Introduction to the SharePoint Framework for developers

Showed: Code running in

‘workbench’ running in Office 365 tenant

Demo explanation - 2

Page 21: Chris O'Brien - Introduction to the SharePoint Framework for developers

Showed: Use of jQuery

AJAX within client web part TypeScript - call SharePoint search API and render results

Simple structure - code all in render() method

Demo explanation - 3

Page 22: Chris O'Brien - Introduction to the SharePoint Framework for developers

Next stepsRefactor into

separate TypeScript

classes/use new SpHttpClient

class

Implement promises (e.g. ES6) for async

methods

Create class/interface to

represent a search result

public GetResultsAsync(query: string, rowLimit: number) : Promise<ISearchResult>

Final code – separate ‘Search’ utility class. GetResultsAsync returns promise with my TS interface representing a search result (with URL, description & title properties):

Page 23: Chris O'Brien - Introduction to the SharePoint Framework for developers

Deploying to production

Page 24: Chris O'Brien - Introduction to the SharePoint Framework for developers

Beyond development modeYour files can be hosted anywhereJavaScript and CSS -> CDN, Azure web app, IIS server, SharePoint library

App packages are the deployment vehicle Upload to App Catalog to make available

Ensure dependencies are bundled OR referencedUpdate config.json if jQuery (or whatever) should be referenced from CDN

Page 25: Chris O'Brien - Introduction to the SharePoint Framework for developers

Deployment process

Build app in release mode

(--ship)

Upload resources to

CDN

Upload app package

(.sppkg) to app catalog

Add to page

Page 26: Chris O'Brien - Introduction to the SharePoint Framework for developers

Deployment steps - detail

1. Upload resources to

CDN• Use supplied

Gulp task (“upload-cdn”), or do it yourself

2. Deal with dependencies

• Ensure 3rd party libraries are bundled OR referenced externally

3. Package app

• Use supplied Gulp task (“gulp package-solution”)

4. Add to app catalog

• Administrator drags and drops into catalog

5. Add to page

• Web part can now be added to page

Page 27: Chris O'Brien - Introduction to the SharePoint Framework for developers

DemoDeploying an SPFx solution to production

Page 28: Chris O'Brien - Introduction to the SharePoint Framework for developers

Showed: Deployment of files

to Azure CDN App deployed to App

Catalog Client web part

available to be added to pages

Demo explanation - 1

Page 29: Chris O'Brien - Introduction to the SharePoint Framework for developers

Other considerations

Page 30: Chris O'Brien - Introduction to the SharePoint Framework for developers

What about on-premises SharePoint?Good news!The SharePoint Framework *is* coming to SP2016 – not just SharePoint Online

Likely to be released in a Feature Pack update, some time in 2017

Page 31: Chris O'Brien - Introduction to the SharePoint Framework for developers

Client web parts in classic pages

New web part properties “wrapped” in old:

Page 32: Chris O'Brien - Introduction to the SharePoint Framework for developers

The security modelThere isn’t one!These are client-side solutions – access to anything in the DOMBUT, some operations are blocked e.g. *some* access to Graph

Provider-hosted add-ins/IFrames are still a good choiceApp parts use IFrames for a reason – security! (Isolated on page)

Create a server-side component (e.g. WebAPI) where necessary

Page 33: Chris O'Brien - Introduction to the SharePoint Framework for developers

Key take-awaysSharePoint dev is changing!TypeScript, npm, gulp and some aspects of node.js are importantLots of framework elements to learn – bundling, APIs, manifest files etc.

SPFx does not replace anythingOffice 365 apps and SP provider-hosted add-ins are still good choices

Start your dev prep now!TypeScript, npm, gulp, and React are good choices

Page 34: Chris O'Brien - Introduction to the SharePoint Framework for developers

Thank you!Any questions?

www.sharepointnutsandbolts.com@ChrisO_Brien