In this article, I have mentioned all steps on deploying SPFx webparts to Azure CDN. It requires some manual steps and some command to create the webparts.
SharePoint Framework has provided ootb supports for deploying to Azure Storage account. Please use Azure Storage account to maintain the web parts.
For the Users who follow Microsoft’s SharePoint framework, while building the SPFx webpart you get your resource files i.e. CSS, JSON etc. You can deploy these resource files on one of the below CDN:
- SharePoint Library in tenant
- Office 365 Public CDN (Content Delivery Network)
- Azure CDN (Content Delivery Network)
Follow the below steps to deploy webpart in Azure CDN:
Create MS Azure Storage Account:
- Open MS Azure Portal (https://portal.azure.com) in any browser and Login.
- Click “Storage accounts”.
- Click “+Create” and enter all the details for your storage account.
Check the following screen shot for all the settings:
4. Fill all the details given below and click “Review +Create”.
5. Go to the Resource.
Create BLOB Container:
- Click on “Containers”.
2. Select “+ container”
3. Give the details and click “ok”.
Storage account access key:
- Select Access Keys in your Containers Settings.
2. Copy one of the access key from key1 or key2.
Enable CDN profile:
- Under “Blob Service”, select “Azure CDN”.
2. Create a new endpoint and Click “Create”
3. The endpoint list appears like this.
Configure SPFx Solution:
- Navigate to SPFx solution folder in command prompt
- To open the webpart project in Visual Studio Code enter “code .”
- Open package-solution.json in the config folder.
- Set “includeClientSideAssets” value as false and “skipFeaturedeployment” value as true.
- To specify the Azure storage account details open deploy-azure-storage.json from config folder
- Update values as below:
3. Open write-manifests.json from config folder and update the path
Prepare Solution to deploy:
- “gulp bundle –ship” run the command on command prompt . The ship switch denotes distribution.
- “gulp package-solution –ship” this command create the solution package in the folder.
Deploy package to SharePoint:
- Open SharePoint app catalog, Upload or drag and drop the client-side solution package to the app catalog
- Select on “Deploy”.
3. Go to your “Site contents” and add your app.
4. Edit page and select your webpart on your webpart picker.
Azure CDN is inexpensive and easy to configure. Azure CDN (Content Delivery Network) is a global cache option to deploy the SPFx client side webpart but always remember that CDN are public and cannot be secured, so the files shouldn't contain sensitive information.