SOLVED

PnP-JS-Core - import only a part & webpack

Copper Contributor

I am using PnP-JS-Core from a simple SharePoint page to gather data from other webs.
using:
import { Web } from "sp-pnp-js/lib/sharepoint/rest/webs";

I am also using WebPack to bundle the solution but I'd like to use pnp.js from our internal CDN and not have everything bundled and create a big output.

I've setup webpack.config.js to not bundle "sp-pnp-js" but I cannot find a way to have that working for "sp-pnp-js/lib/sharepoint/rest/webs"

externals: {
// Do not bundle package PnP JS
"sp-pnp-js": "$pnp",
"sp-pnp-js/lib/sharepoint/rest/webs": ????
}

Any idea how to solve that ?

1 Reply
best response confirmed by Djemel Guizani (Copper Contributor)
Solution

Hello Djemel,

 

With the release of 1.0.5 this week we now support this scenario by exporting many of the objects to the root level. So if you do:

 

import { Web } from "sp-pnp-js";

 

let w = new Web("your full url");

 

w.get().then(...)

 

That should now be webpack friendly.

1 best response

Accepted Solutions
best response confirmed by Djemel Guizani (Copper Contributor)
Solution

Hello Djemel,

 

With the release of 1.0.5 this week we now support this scenario by exporting many of the objects to the root level. So if you do:

 

import { Web } from "sp-pnp-js";

 

let w = new Web("your full url");

 

w.get().then(...)

 

That should now be webpack friendly.

View solution in original post