To change the package name, if needed, it can be done from package-solution.json file which can be found under config folder as the value of zippedPackege property, location: [./config/ package-solution.json].
Now open the node.js common prompt. And change the base path to the working solution folder. First, in the command line, execute the command"gulp clean"
as this will clean all the previous build files if there are any already.
Fig: node command prompt – Running the gulp clean command
Now, run and execute the "gulp bundle --ship"
command to build the project files on which the output files of this command are located in the ./temp/deploy folder as specified in the write-manifests.json file. These are the files that in a moment you will upload to the web part folder.
Fig: Web-part files Compiling and their output
To generate the package run the "gulp package-solution --ship"
command in the node.js command prompt. A file with .sppkg extension will be generated by containing the information about the web parts in your project and where they are hosted. The generated file will be located in the ./sharepoint/deploy folder.
Fig: Generating the Package File of the SPFx Project
So, we make a summery as we had to run three consecutive command lines to complete the package building and related files compilation process. The commands are here below to make it easier to understand for the readers.
- gulp clean //To clean the previous compiled files
- gulp bundle –ship // To Compile the web-part files
- gulp package-solution –ship //To Generate the package file
Upload web part files and Deploy the Package File
As the project is already built and packaged, it's ready to be deployed. Web part files are needed to be uploaded in the web-part folder first and then the package file with .sppkg extension needs to deploy in the app catalog. So, to upload the files, go to the ./temp/deploy folder of your project and upload all files to the web part folder in your CDN folder which we have already created in the first part of our article.
File: Upload the Web-part files
Now, we need to deploy the package file as it will help to use your web parts in SharePoint. The package file needs to be deployed in the app catalog of your Office 365 tenant on which tenant the target site exists. At this moment, deploying.sppkg files to app catalog is possible only in developer tenants, otherwise deploying in different tenants will get an error. To deploy the .sppkg file in the app catalog, open the app catalog site and from the menu navigate to the Apps for SharePoint page and deploy it.
Fig: Deploy the Package File in App Catalog
Install the App on the Site
As all the package and web-part files are deployed accordingly, now start using them on your site. But SharePoint Framework web parts are distributed similarly to SharePoint add-ins, so first we need to add the app to the site. In the target site, navigate to the Site contents view and from the menu choose New App option. Now, search for your solution name and the app will be found.
Fig: Installing SPFx App on the Site
After adding the app in the site, now add the SPFx client-side web parts to pages or in List form as you need in the same way you would add any other web part in SharePoint. The SPFXs will be displayed in the Custom category in the web part gallery as configured under preconfiguredEntries in >/<WebPartName>.manifest.json file at the time of web-part configuration.
Conclusion
If the steps are being followed correctly, the SPFx client-side web part will work correctly and will be loaded from your Office 365 private CDN. There are some complications to use the same web-part with a different version in a different site under the same tenant for staging and production use. But there is some workaround to achieve this which will I describe in my next article.