5

I found some articles which are explaining creating modern sites with CSOM. But I am not able to find in JavaScript to use in SPFx. Creating modern sites is supported with SPFx? Any PnP extension available for this?

2 Answers 2

7

You can use the PnPJS to create modern team and communication sites.

For that, simply add the below packages:

npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save

After that, you can add the below import statement:

import { sp } from "@pnp/sp";

And in the webpart, you can use it as below to create modern sites:

1) Modern communication sites:

sp.site.createCommunicationSite(
            "Comm Site Title",
            1033,
            true,
            "https://tenant.sharepoint.com/sites/commSite",
            ).then(d => {
                console.log(d);
            });

2) Modern team site:

sp.site.createModernTeamSite(
        "displayName",
        "alias",
        true,
        1033,
        "description",
        "",
        ["[email protected]","[email protected]","[email protected]"])
        .then(d => {
            console.log(d);
        });

Reference - PnPJS Sites

1
  • 1
    I don't see the point to have two identical answers.. so deleted mine despite I answered a bit earlier than you... Dec 7, 2018 at 14:52
5

You can do that with the most recent version (1.2.6) of PnPjs library:

import { sp } from "@pnp/sp";

sp.site.createModernTeamSite(
        "displayName",
        "alias",
        true,
        1033,
        "description",
        "HBI",
        ["[email protected]","[email protected]","[email protected]"])
        .then(d => {
            console.log(d);
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.