Skip to content

Commit 2ee974a

Browse files
committed
Upgraded to SPFx 1.8 and added automated deployment
1 parent f83e5d7 commit 2ee974a

24 files changed

Lines changed: 9922 additions & 12838 deletions

.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"webRoot": "${workspaceRoot}",
1313
"sourceMaps": true,
1414
"sourceMapPathOverrides": {
15+
"webpack:///.././src/*": "${webRoot}/src/*",
1516
"webpack:///../../../src/*": "${webRoot}/src/*",
1617
"webpack:///../../../../src/*": "${webRoot}/src/*",
1718
"webpack:///../../../../../src/*": "${webRoot}/src/*"
@@ -28,6 +29,7 @@
2829
"webRoot": "${workspaceRoot}",
2930
"sourceMaps": true,
3031
"sourceMapPathOverrides": {
32+
"webpack:///.././src/*": "${webRoot}/src/*",
3133
"webpack:///../../../src/*": "${webRoot}/src/*",
3234
"webpack:///../../../../src/*": "${webRoot}/src/*",
3335
"webpack:///../../../../../src/*": "${webRoot}/src/*"

.yo-rc.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"@microsoft/generator-sharepoint": {
33
"isCreatingSolution": true,
44
"environment": "spo",
5-
"version": "1.6.0",
5+
"version": "1.8.0",
66
"libraryName": "react-application-injectcss",
7-
"libraryId": "b2322574-549b-4510-99d8-1351d9457a97",
7+
"libraryId": "1a07c460-c268-4569-beff-579c18de692b",
88
"packageManager": "npm",
9+
"isDomainIsolated": false,
910
"componentType": "extension",
1011
"extensionType": "ApplicationCustomizer"
1112
}
12-
}
13+
}

DeployApplicationCustomizer.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use this file to deploy the extension to your application catalog
2+
#$tenantUrl = "https://<your-tenant>.sharepoint.com"
3+
$tenantUrl = "https://ashbay16.sharepoint.com"
4+
5+
# Get credentials
6+
$credentials = Get-Credential
7+
Connect-PnPOnline $tenantUrl -Credentials $credentials
8+
9+
Add-PnPApp -path .\sharepoint\solution\react-application-injectcss.sppkg -Publish -SkipFeatureDeployment -Overwrite

DisableApplicationCustomizer.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$tenantUrl = "https://<your-tenant>.sharepoint.com/sites/<your-site>"
2+
3+
# Get credentials
4+
$credentials = Get-Credential
5+
Connect-PnPOnline $tenantUrl -Credentials $credentials
6+
7+
# Connect to tenant
8+
Get-PnPCustomAction | ? Name -eq "InjectCssApplicationCustomizer" | Remove-PnPCustomAction
9+

EnableApplicationCustomizer.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Change these variables to enable the extension
2+
$customCSSUrl = "/Style%20Library/custom.css"
3+
$tenantUrl = "https://<your-tenant>.sharepoint.com/sites/<your-site>"
4+
5+
# Get credentials
6+
$credentials = Get-Credential
7+
Connect-PnPOnline $tenantUrl -Credentials $credentials
8+
9+
# Connect to tenant
10+
$context = Get-PnPContext
11+
$web = Get-PnPWeb
12+
$context.Load($web)
13+
Invoke-PnPQuery
14+
15+
# Deploy custom action
16+
$ca = $web.UserCustomActions.Add()
17+
$ca.ClientSideComponentId = "5a1fcffd-dfeb-4844-b478-1feb4325a5a7"
18+
$ca.ClientSideComponentProperties = "{""cssurl"":""$customCSSUrl""}"
19+
$ca.Location = "ClientSideExtension.ApplicationCustomizer"
20+
$ca.Name = "InjectCssApplicationCustomizer"
21+
$ca.Title = "Inject CSS Application Extension"
22+
$ca.Description = "Injects custom CSS to make minor style modifications to SharePoint Online"
23+
$ca.Update()
24+
25+
$context.Load($web.UserCustomActions)
26+
Invoke-PnPQuery
27+

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Spfx Applications Customiser CSS Injection
1+
# SPFx Applications Customiser CSS Injection
22

33
## Summary
4+
45
This sample shows how to inject a custom Cascading Style Sheet (CSS) on modern pages.
56

67
![Sample super ugly CSS to illustrate custom CSS injection](./assets/sampleresults.png)
78

8-
__Note__: This code is provided as a sample only. Keep in mind that Microsoft may change page elements and styles at any time, rendering your custom CSS useless. It is preferrable to use well-known HTML element placeholders.
9+
> **Note**: This code is provided as a sample only. Keep in mind that Microsoft may change page elements and styles at any time, rendering your custom CSS useless. It is preferrable to use well-known HTML element placeholders.
910
1011
When you need to make minor cosmetic changes to modern pages (e.g.: match your corporate branding guidelines) and cannot use placeholders,you can create a custom CSS and inject on every modern page.
1112

1213
In this example, we deploy the CSS in a shared location; this allows us to change the CSS file at any time without re-deploying or re-configuring the application customizer.
1314

1415
You can deploy the application customizer with different settings to point to different CSS files.
1516

17+
Please refrain from making drastic changes that may negatively impact your users' experience. If you experience issues with modern pages, please try disabling the extension before calling Microsoft Support to ensure that the issue isn't caused by your custom CSS.
1618

1719
## Used SharePoint Framework Version
1820

19-
![SPFx v1.6](https://img.shields.io/badge/SPFx-1.6-green.svg)
21+
![SPFx v1.8](https://img.shields.io/badge/SPFx-1.8-green.svg)
2022

2123
## Applies to
2224

@@ -35,6 +37,7 @@ Version|Date|Comments
3537
-------|----|--------
3638
1.0.0|07 May, 2018|Initial release
3739
1.1.0|18 October, 2018|Updated to SPFx 1.6
40+
1.2.0|28 March, 2018|Updated to SPFx 1.8
3841

3942
## Disclaimer
4043

@@ -44,37 +47,77 @@ Version|Date|Comments
4447

4548
## Minimal Path to Awesome
4649

47-
* clone repo
48-
* create a custom CSS file that meets your needs. For example, this CSS will make the site logos round and will add an ugly red colour at the top of every page.
50+
### Prepare the assets
4951

52+
1. create a custom CSS file that meets your needs. For example, this CSS will change the feedback button's background color to orange.
53+
54+
```CSS
55+
.sitePage-uservoice-button {
56+
background-color: orange;
57+
}
5058
```
51-
.ms-compositeHeader {
52-
background-color: red;
53-
}
54-
55-
.ms-siteLogoContainerOuter {
56-
border-radius: 50%;
57-
border-width: 3px;
58-
}
59-
60-
.ms-siteLogo-actual {
61-
border-radius: 50%;
62-
}
63-
```
64-
* Upload the CSS file to a shared location on your SharePoint tenant. For example, in the `Styles Library` of the root site collection.
65-
* Get the URL to your custom CSS. For example: `/Style%20Library/custom.css`
6659

67-
* Update _serve.json_ pointing to your site collection home page change the `cssurl` property with the URL to your custom CSS.
68-
* Run _gulp serve_
60+
2. Upload the CSS file as `custom.css` to your `Styles Library` of the root site collection (i.e.: `https://<yourtenant>.sharepoint.com/Style%20Library/Forms/AllItems.aspx`).
61+
3. Navigate to your site. Your custom CSS should be applied.
62+
63+
For example, the CSS provided above will make the feedback button appear as follows:
64+
![Orange Feedback](./assets/orangeisthenewfeedback.png)
65+
66+
### Build the solution
67+
68+
1. clone repo
69+
2. Run `gulp bundle --ship`
70+
3. Run `gulp package-solution --ship`
71+
72+
### Manual deployment
73+
74+
1. Upload the `react-application-injectcss.sppkg` from the `sharepoint` folder to your App catalog.
75+
2. When prompted to deploy to all sites, choose the option that suits your needs.
76+
77+
### Automated deployment
78+
79+
1. If you have not done so already, install the [PnP PowerShell Cmdlets](https://aka.ms/sppnp-powershell)
80+
2. Edit the `DeployApplicationCustomizer.ps1` file and change the `$tenantUrl` variable to point to your tenant.
81+
3. From a PowerShell console, run the `DeployApplicationCustomizer.ps1` script to automatically deploy to all sites.
82+
4. You will be prompted to enter your credentials.
83+
5. After providing your credentials, the extension will be deployed
84+
85+
## Changing the CSS location
86+
87+
To simplify deployment, the extension looks for a `custom.css` in your tenant's root `Style Library`. If you wish to use a different CSS name and location, use one of the following approaches:
88+
89+
### In the solution
90+
91+
This approach will change the default css location in the solution so that it will automatically load your custom CSS when the extension is deployed.
92+
93+
Note that if you intend to deploy this extension tenant-wide, your custom CSS URL should be an absolute URL or a server-relative URL.
94+
95+
1. Locate the `elements.xml` file, in the `sharepoint` > `assets` folder
96+
2. Change the `ClientSideComponentProperties` to point to your custom CSS URL.
97+
3. Run `gulp bundle --ship`
98+
4. Run `gulp package-solution --ship`
99+
5. Upload the `react-application-injectcss.sppkg` from the `sharepoint` folder to your App catalog.
100+
6. When prompted to deploy to all sites, choose the option that suits your needs.
101+
102+
### Using automated deployment
103+
104+
This approach allows you to override the CSS location by configuring the extension properties as the extension is activated.
105+
106+
1. Edit the `EnableApplicationCustomizer.ps1` file and change the `$tenantUrl` variable to point to your tenant.
107+
2. In the same file, change the `$customCSSUrl` variable to point to your custom CSS URL.
108+
3. From a PowerShell console, run the `EnableApplicationCustomizer.ps1` script to automatically deploy to all sites.
109+
4. You will be prompted to enter your credentials.
110+
5. After providing your credentials, the extension will be deployed using your custom CSS URL.
111+
112+
## Disabling the extension
69113

70-
## Deployment to Production
114+
1. Edit the `DisableApplicationCustomizer.ps1` file and change the `$tenantUrl` variable to point to your tenant.
115+
2. From a PowerShell console, run the `DisableApplicationCustomizer.ps1` script to automatically deploy to all sites.
116+
3. You will be prompted to enter your credentials.
117+
4. If prompted to remove the application, choose Yes.
118+
5. The extension will be removed.
71119

72-
* Locate the `elements.xml` file, in the `sharepoint` > `assets` folder
73-
* Change the `ClientSideComponentProperties` to point to your custom CSS URL.
74-
* Run _gulp bundle --ship_
75-
* Run _gulp package-solution --ship_
76-
* Upload the `react-application-injectcss.sppkg` from the `sharepoint` folder to your App catalog.
77-
* When prompted to deploy to all sites, choose the option that suits your needs.
120+
If you wish to do so, you can remove the solution package from your tenant's app catalog after the extension has been de-activated.
78121

79122
## Features
80123

assets/orangeisthenewfeedback.png

2.5 KB
Loading
-7.04 KB
Binary file not shown.

config/deploy-azure-storage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"account": "<!-- STORAGE ACCOUNT NAME -->",
55
"container": "react-application-injectcss",
66
"accessKey": "<!-- ACCESS KEY -->"
7-
}
7+
}

0 commit comments

Comments
 (0)