Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Deployment

Patrick Rodgers edited this page Mar 10, 2017 · 4 revisions

There are three main ways to consume the library in a production deployment: copy the file to your servers, bundle the code into your solution (such as with webpack), or reference the code from a CDN. These methods are outlined here but this is not meant to be an exhaustive guide on all the ways to package and deploy solutions.

Copy the Files Locally

This option requires you to ensure that you are keeping the library up to date but is sometimes the only option when working in an environment where public internet access is blocked. The recommended approach is to create an internal CDN such that all of your applications making use of the pnp.js or pnp.min.js files can use the same copy - making updates easier.

To get the latest version just copy the files you need from the dist folder to your local CDN or application.

Bundle

If you have installed the library via NPM solution bundlers such as webpack can bundle the pnp js core along with your solution. This can make deployment easier, but will increase the size of your code by the size of the library. There are techniques under development such as tree shaking to help you only include the parts of the library you need in your bundles. With the release of 2.0 the lib folder distributed in the pnp-js-core package is transpiled into es6, which should support the latest features of various bundlers.

CDN

If you have public internet access you can reference the library from the cdnjs CDN which maintains copies of all versions. This is ideal as you do not need to host the file yourself, and it is easy to update to a newer release by updating the URL in your solution.

CDN and SPFx

If you are developing in SPFx and install and import sp-pnp-js the default behavior will be to bundle the library into your solution. If you are able it is recommended to reference the library as an external library by updating the SPFx config/config.js to include this line in the externals section:

"sp-pnp-js": "https://cdnjs.cloudflare.com/ajax/libs/sp-pnp-js/2.0.2/pnp.min.js"

Don't forget to update the version number in the url to match the version you want to use. This will stop the library from being bundled directly into the solution and instead use the copy from the CDN. When a new version of sp-pnp-js is released and you are ready to update just update this url in your SPFX project's config.js file.

Clone this wiki locally