Use a supported workaround to get the script root.

This commit is contained in:
Mikael Svenson 2018-08-20 12:08:16 +02:00
parent ec192e1c62
commit b3a87a7672
2 changed files with 10 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

View File

@ -36,11 +36,7 @@ export default class ScriptEditorWebPart extends BaseClientSideWebPart<IScriptEd
this.executeScript(this.domElement); this.executeScript(this.domElement);
} else { } else {
// Dynamically load the editor pane to reduce overall bundle size // Dynamically load the editor pane to reduce overall bundle size
let scriptRoot = (<any>this.context.manifest).loaderConfig.internalModuleBaseUrls[0]; const editorPopUp: any = await SPComponentLoader.loadScript(this.getScriptRoot() + '/editor-pop-up.min.js', { globalExportsName: "EditorPopUp" });
if (scriptRoot.indexOf("localhost") != -1) {
scriptRoot += "dist/";
}
const editorPopUp: any = await SPComponentLoader.loadScript(scriptRoot + '/editor-pop-up.min.js', { globalExportsName: "EditorPopUp" });
const element: React.ReactElement<IScriptEditorProps> = React.createElement( const element: React.ReactElement<IScriptEditorProps> = React.createElement(
editorPopUp.default, editorPopUp.default,
{ {
@ -53,6 +49,15 @@ export default class ScriptEditorWebPart extends BaseClientSideWebPart<IScriptEd
} }
} }
/**
* Use a dummy bundled image to get the path from where the bundle is served.
*/
private getScriptRoot(): string {
const runtimePath: string = require('./1x1.png');
const scriptRoot = runtimePath.substr(0, runtimePath.lastIndexOf("/"));
return scriptRoot;
}
protected get dataVersion(): Version { protected get dataVersion(): Version {
return Version.parse('1.0'); return Version.parse('1.0');
} }