Upgrade js-dynamic-bundling-libraries to SPFx 1.7.0 (#709)

* Dynamic SPFx Bundling Initial Commit

* Upgrade to SPFx v1.7.0
This commit is contained in:
David Warner II 2018-12-08 08:57:35 -08:00 committed by Vesa Juvonen
parent e69d235991
commit 420693e52d
27 changed files with 2641 additions and 3390 deletions

View File

@ -1,25 +1,25 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 2
# we recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[{package,bower}.json]
indent_style = space
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 2
# we recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[{package,bower}.json]
indent_style = space
indent_size = 2

View File

@ -1,32 +1,32 @@
# Logs
logs
*.log
npm-debug.log*
# Dependency directories
node_modules
# Build generated files
dist
lib
#solution
temp
#*.sppkg
# Coverage directory used by tools like istanbul
coverage
# OSX
.DS_Store
# Visual Studio files
.ntvs_analysis.dat
.vs
bin
obj
# Resx Generated Code
*.resx.ts
# Styles Generated Code
*.scss.ts
# Logs
logs
*.log
npm-debug.log*
# Dependency directories
node_modules
# Build generated files
dist
lib
#solution
temp
#*.sppkg
# Coverage directory used by tools like istanbul
coverage
# OSX
.DS_Store
# Visual Studio files
.ntvs_analysis.dat
.vs
bin
obj
# Resx Generated Code
*.resx.ts
# Styles Generated Code
*.scss.ts

View File

@ -1,11 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.6.0",
"libraryName": "dynamic-bundling",
"libraryId": "c40970b0-7ef0-40f2-b03b-718751fbc4b5",
"packageManager": "npm",
"componentType": "webpart"
}
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.7.0",
"libraryName": "dynamic-bundling",
"libraryId": "c40970b0-7ef0-40f2-b03b-718751fbc4b5",
"packageManager": "npm",
"componentType": "webpart",
"isDomainIsolated": false
}
}

View File

@ -1,59 +1,60 @@
# title of the sample
## Summary
This sample illustrates how SPFx functionality and packages can be bundled in multiple '.js' files then be dynamically & asynchronously loaded into the page at execution time, such as with a button click.
Pre Button Click:
![preview](./assets/WebPart-Preview-PreClick.jpg)
Post Button Click that imports jQuery and additional functionality:
![preview](./assets/WebPart-Preview-PostjQueryClick.jpg)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/drop-1.6.0-blue.svg)
## Applies to
* [SharePoint Framework](https:/dev.office.com/sharepoint)
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
## Solution
Solution|Author(s)
--------|---------
js-dynamic-bundling-libaries | David Warner II ([@DavidWarnerII](https://twitter.com/davidwarnerii) / [Warner Digital](http://warner.digital))
## Version history
Version|Date|Comments
-------|----|--------
1.0|September 21, 2018|Initial release
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
---
## Minimal Path to Awesome
- Clone this repository
- in the command line run:
- `npm install`
- `gulp serve`
## Features
This Web Part illustrates the following concepts on top of the SharePoint Framework:
- How to separate SPFx functionality into multiple bundled files
- How to asynchronously load the seperate bundled files at execution time
- Including a library in the separate bundled file.
## Additional Information:
- [Dynamic loading of packages in SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/dynamic-loading)
- Video Demonstration on using, building and code specifics for the sample web part:<br> http://warner.digital/dynamic-spfx-package-bundling/
# title of the sample
## Summary
This sample illustrates how SPFx functionality and packages can be bundled in multiple '.js' files then be dynamically & asynchronously loaded into the page at execution time, such as with a button click.
Pre Button Click:
![preview](./assets/WebPart-Preview-PreClick.jpg)
Post Button Click that imports jQuery and additional functionality:
![preview](./assets/WebPart-Preview-PostjQueryClick.jpg)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/drop-1.7.0-orange.svg)
## Applies to
* [SharePoint Framework](https:/dev.office.com/sharepoint)
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
## Solution
Solution|Author(s)
--------|---------
js-dynamic-bundling-libaries | David Warner II ([@DavidWarnerII](https://twitter.com/davidwarnerii) / [Warner Digital](http://warner.digital))
## Version history
Version|Date|Comments
-------|----|--------
1.0|September 21, 2018|Initial release
1.1|December 3, 2018|Updated for SPFx 1.7.0
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
---
## Minimal Path to Awesome
- Clone this repository
- in the command line run:
- `npm install`
- `gulp serve`
## Features
This Web Part illustrates the following concepts on top of the SharePoint Framework:
- How to separate SPFx functionality into multiple bundled files
- How to asynchronously load the seperate bundled files at execution time
- Including a library in the separate bundled file.
## Additional Information:
- [Dynamic loading of packages in SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/dynamic-loading)
- Video Demonstration on using, building and code specifics for the sample web part:<br> http://warner.digital/dynamic-spfx-package-bundling/
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/readme-template" />

View File

@ -1,18 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"dynamic-bundling-example-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/dynamicBundlingExample/DynamicBundlingExampleWebPart.js",
"manifest": "./src/webparts/dynamicBundlingExample/DynamicBundlingExampleWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"DynamicBundlingExampleWebPartStrings": "lib/webparts/dynamicBundlingExample/loc/{locale}.js"
}
}
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"dynamic-bundling-example-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/dynamicBundlingExample/DynamicBundlingExampleWebPart.js",
"manifest": "./src/webparts/dynamicBundlingExample/DynamicBundlingExampleWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"DynamicBundlingExampleWebPartStrings": "lib/webparts/dynamicBundlingExample/loc/{locale}.js"
}
}

View File

@ -1,4 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -1,7 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "dynamic-bundling",
"accessKey": "<!-- ACCESS KEY -->"
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "dynamic-bundling",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -1,12 +1,13 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "dynamic-bundling-client-side-solution",
"id": "c40970b0-7ef0-40f2-b03b-718751fbc4b5",
"version": "1.0.0.0",
"includeClientSideAssets": true
},
"paths": {
"zippedPackage": "solution/dynamic-bundling.sppkg"
}
}
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "dynamic-bundling-client-side-solution",
"id": "c40970b0-7ef0-40f2-b03b-718751fbc4b5",
"version": "1.1.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/dynamic-bundling.sppkg"
}
}

View File

@ -1,10 +1,10 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
}
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
}

View File

@ -1,4 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -1,7 +1,7 @@
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.initialize(gulp);
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.initialize(gulp);

File diff suppressed because it is too large Load Diff

View File

@ -11,23 +11,22 @@
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.6.0",
"@microsoft/sp-lodash-subset": "1.6.0",
"@microsoft/sp-office-ui-fabric-core": "1.6.0",
"@microsoft/sp-webpart-base": "1.6.0",
"@microsoft/sp-core-library": "1.7.0",
"@microsoft/sp-lodash-subset": "1.7.0",
"@microsoft/sp-office-ui-fabric-core": "1.7.0",
"@microsoft/sp-webpart-base": "1.7.0",
"@types/es6-promise": "0.0.33",
"@types/jquery": "^3.3.6",
"@types/webpack-env": "1.13.1",
"jquery": "^3.3.1"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.6.0",
"@microsoft/sp-module-interfaces": "1.6.0",
"@microsoft/sp-webpart-workbench": "1.6.0",
"tslint-microsoft-contrib": "~5.0.0",
"gulp": "~3.9.1",
"@microsoft/sp-build-web": "1.7.0",
"@microsoft/sp-module-interfaces": "1.7.0",
"@microsoft/sp-webpart-workbench": "1.7.0",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
"ajv": "~5.2.2",
"gulp": "~3.9.1"
}
}

View File

@ -1 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler
// A file is required to be in the root of the /src directory by the TypeScript compiler

View File

@ -1,26 +1,26 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "5378270a-cb87-4be2-b3b7-0ddf597fd77d",
"alias": "DynamicBundlingExampleWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Dynamic Bundling Example" },
"description": { "default": "Dynamic Bundling Example description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Dynamic Bundling Example"
}
}]
}
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "5378270a-cb87-4be2-b3b7-0ddf597fd77d",
"alias": "DynamicBundlingExampleWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Dynamic Bundling Example" },
"description": { "default": "Dynamic Bundling Example description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Dynamic Bundling Example"
}
}]
}

View File

@ -1,77 +1,77 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.dynamicBundlingExample {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
width:90% !important;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
width:100% !important;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.dynamicBundlingExample {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
width:90% !important;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
width:100% !important;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -1,101 +1,101 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './DynamicBundlingExampleWebPart.module.scss';
import * as strings from 'DynamicBundlingExampleWebPartStrings';
export interface IDynamicBundlingExampleWebPartProps {
description: string;
}
export default class DynamicBundlingExampleWebPart extends BaseClientSideWebPart<IDynamicBundlingExampleWebPartProps> {
public render(): void {
this.domElement.innerHTML = `
<div class="${ styles.dynamicBundlingExample }">
<div class="${ styles.container }">
<div class="${ styles.row }">
<div class="${ styles.column }">
<span class="${ styles.title }">Dynamic Bundling & Loading of SPFx Packages</span>
<p class="${ styles.subTitle }">When the buttons below are clicked, the associated ".ts" file and it's functionality will be loaded.</p>
<a id="ImportButton" href="#" class="${ styles.button }">
<span class="${ styles.label }">Dynamically Import Functionality</span>
</a>
<a id="ImportButtonJQuery" href="#" class="${ styles.button }">
<span class="${ styles.label }">Dynamically Import Functionality w/ jQuery</span>
</a>
</div>
<div class="insertHTML"></div>
</div>
</div>
</div>`;
this.setupClickEvent();
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
// Create a click event listener for the ImportButton Anchor element
public setupClickEvent(): void {
let btn = document.getElementById("ImportButton");
btn.addEventListener("click", (e:Event) => this.dynamicallyImportFunctions());
let btnjQuery = document.getElementById("ImportButtonJQuery");
btnjQuery.addEventListener("click", (e:Event) => this.dynamicallyImportFunctionsJQuery());
}
// This will setup the 'DynamicImportedFunctions.ts' to be bundled into a separate .js file.
protected async dynamicallyImportFunctions() {
const importedTS = await import(
'./DynamicImportedFunctions'
)
importedTS.default.executeDynamicLoad();
}
//This will setup the 'DynamicImportedFunctionsJQuery.ts' to be bundled into a separate .js file.
protected async dynamicallyImportFunctionsJQuery() {
const importedJQueryTS = await import(
'./DynamicImportedFunctionsJQuery'
)
importedJQueryTS.default.executeDynamicLoadJQuery();
importedJQueryTS.default.addToDOM(this.domElement);
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './DynamicBundlingExampleWebPart.module.scss';
import * as strings from 'DynamicBundlingExampleWebPartStrings';
export interface IDynamicBundlingExampleWebPartProps {
description: string;
}
export default class DynamicBundlingExampleWebPart extends BaseClientSideWebPart<IDynamicBundlingExampleWebPartProps> {
public render(): void {
this.domElement.innerHTML = `
<div class="${ styles.dynamicBundlingExample }">
<div class="${ styles.container }">
<div class="${ styles.row }">
<div class="${ styles.column }">
<span class="${ styles.title }">Dynamic Bundling & Loading of SPFx Packages</span>
<p class="${ styles.subTitle }">When the buttons below are clicked, the associated ".ts" file and it's functionality will be loaded.</p>
<a id="ImportButton" href="#" class="${ styles.button }">
<span class="${ styles.label }">Dynamically Import Functionality</span>
</a>
<a id="ImportButtonJQuery" href="#" class="${ styles.button }">
<span class="${ styles.label }">Dynamically Import Functionality w/ jQuery</span>
</a>
</div>
<div class="insertHTML"></div>
</div>
</div>
</div>`;
this.setupClickEvent();
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
// Create a click event listener for the ImportButton Anchor element
public setupClickEvent(): void {
let btn = document.getElementById("ImportButton");
btn.addEventListener("click", (e:Event) => this.dynamicallyImportFunctions());
let btnjQuery = document.getElementById("ImportButtonJQuery");
btnjQuery.addEventListener("click", (e:Event) => this.dynamicallyImportFunctionsJQuery());
}
// This will setup the 'DynamicImportedFunctions.ts' to be bundled into a separate .js file.
protected async dynamicallyImportFunctions() {
const importedTS = await import(
'./DynamicImportedFunctions'
)
importedTS.default.executeDynamicLoad();
}
//This will setup the 'DynamicImportedFunctionsJQuery.ts' to be bundled into a separate .js file.
protected async dynamicallyImportFunctionsJQuery() {
const importedJQueryTS = await import(
'./DynamicImportedFunctionsJQuery'
)
importedJQueryTS.default.executeDynamicLoadJQuery();
importedJQueryTS.default.addToDOM(this.domElement);
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -1,15 +1,15 @@
/*
This file demonstrates how we can separate functionality that might not need to be loaded with the SPFx Web Part or Extension immediately, but be bundled into a separate .js file and loaded dynamically.
This function will write a message to the console when it is dynamcially loaded.
*/
export default class DynamicFunctions {
public static executeDynamicLoad():void {
console.log('Dynamic Functionality has been imported');
}
}
/*
This file demonstrates how we can separate functionality that might not need to be loaded with the SPFx Web Part or Extension immediately, but be bundled into a separate .js file and loaded dynamically.
This function will write a message to the console when it is dynamcially loaded.
*/
export default class DynamicFunctions {
public static executeDynamicLoad():void {
console.log('Dynamic Functionality has been imported');
}
}

View File

@ -1,6 +1,6 @@
.injectedContent {
clear:both;
padding-top:20px;
margin-left:60px;
font-size:20px;
}
.injectedContent {
clear:both;
padding-top:20px;
margin-left:60px;
font-size:20px;
}

View File

@ -1,32 +1,32 @@
/*
This file demonstrates how we can separate functionality that might not need to be loaded with the SPFx Web Part or Extension immediately, but be bundled into a separate .js file and loaded dynamically.
We will be bundling jQuery in the imported .ts file.
This demonstrates how if we have the need to bundle a third party library, such as jQuery, we can delay the loading of it as well as any additional functionality until aboslutely needed.
This example will add a CSS class to the <body> element, write a message to the console and inject some HTML letting us know that jQuery has been loaded.
*/
import * as $ from 'jquery';
require('./DynamicImportedFunctionsJQuery.scss');
export default class DynamicFunctionsJQuery {
public static executeDynamicLoadJQuery():void {
console.log('Dynamic Functionality with jQuery has been imported');
$('body').addClass('jQueryImported');
}
public static addToDOM(webpart:HTMLElement){
//console.log(webpart);
var item = webpart.getElementsByClassName('insertHTML')[0];
item.innerHTML = `
<div class="injectedContent">
<span class="">jQuery has been dynamically imported.</span>
</div>
`
}
}
/*
This file demonstrates how we can separate functionality that might not need to be loaded with the SPFx Web Part or Extension immediately, but be bundled into a separate .js file and loaded dynamically.
We will be bundling jQuery in the imported .ts file.
This demonstrates how if we have the need to bundle a third party library, such as jQuery, we can delay the loading of it as well as any additional functionality until aboslutely needed.
This example will add a CSS class to the <body> element, write a message to the console and inject some HTML letting us know that jQuery has been loaded.
*/
import * as $ from 'jquery';
require('./DynamicImportedFunctionsJQuery.scss');
export default class DynamicFunctionsJQuery {
public static executeDynamicLoadJQuery():void {
console.log('Dynamic Functionality with jQuery has been imported');
$('body').addClass('jQueryImported');
}
public static addToDOM(webpart:HTMLElement){
//console.log(webpart);
var item = webpart.getElementsByClassName('insertHTML')[0];
item.innerHTML = `
<div class="injectedContent">
<span class="">jQuery has been dynamically imported.</span>
</div>
`
}
}

View File

@ -1,7 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -1,10 +1,10 @@
declare interface IDynamicBundlingExampleWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'DynamicBundlingExampleWebPartStrings' {
const strings: IDynamicBundlingExampleWebPartStrings;
export = strings;
}
declare interface IDynamicBundlingExampleWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'DynamicBundlingExampleWebPartStrings' {
const strings: IDynamicBundlingExampleWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,47 @@
{
"": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.2/MicrosoftTeams.schema.json",
"manifestVersion": "1.2",
"packageName": "Dynamic Bundling Example",
"id": "5378270a-cb87-4be2-b3b7-0ddf597fd77d",
"version": "0.1",
"developer": {
"name": "SPFx + Teams Dev",
"websiteUrl": "https://products.office.com/en-us/sharepoint/collaboration",
"privacyUrl": "https://privacy.microsoft.com/en-us/privacystatement",
"termsOfUseUrl": "https://www.microsoft.com/en-us/servicesagreement"
},
"name": {
"short": "Dynamic Bundling Example"
},
"description": {
"short": "Dynamic Bundling Example description",
"full": "Dynamic Bundling Example description"
},
"icons": {
"outline": "tab20x20.png",
"color": "tab96x96.png"
},
"accentColor": "#004578",
"configurableTabs": [
{
"configurationUrl": "https://{teamSiteDomain}{teamSitePath}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest={teamSitePath}/_layouts/15/teamshostedapp.aspx%3FopenPropertyPane=true%26teams%26componentId=5378270a-cb87-4be2-b3b7-0ddf597fd77d",
"canUpdateConfiguration": true,
"scopes": [
"team"
]
}
],
"validDomains": [
"*.login.microsoftonline.com",
"*.sharepoint.com",
"*.sharepoint-df.com",
"spoppe-a.akamaihd.net",
"spoprod-a.akamaihd.net",
"resourceseng.blob.core.windows.net",
"msft.spoppe.com"
],
"webApplicationInfo": {
"resource": "https://{teamSiteDomain}",
"id": "00000003-0000-0ff1-ce00-000000000000"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1,34 +1,34 @@
{
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}
{
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -1,32 +1,31 @@
{
"rulesDirectory": [
"tslint-microsoft-contrib"
],
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
{
"rulesDirectory": [],
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}