Reference a Third Party Library for Web Application Environments
You can reference external JavaScript libraries to augment custom activities or custom form elements.
Prerequisites
Follow the instructions in the Web Applications SDK page to set up your development environment.
note
A working knowledge of TypeScript is recommended before extending Workflow for web-based hosts.
Adding a Dependency
- Install the dependency in the activity sdk. For example,
npm install moment
. - Copy the dependency to
dist/deps/
.
important
It's important that you copy and not move the dependency from the node_modules
folder, as this will make it accessible to both the development server and production activity pack.
- Add a call to
mapDependencies()
to theconfigure()
method insrc/main.ts
.
For example, if you wanted to use the moment.js library and had the file moment.js
located in a folder called deps/moment
within the dist
folder, you would write the following:
The root that the library path refers to is the dist
folder, and the .js
suffix on the library file should be omitted.
- Import and use the library as you normally would use a javascript library. This example demonstrates a custom activity that uses the
moment.js
library to return the current date and time in a human readable format.
important
If the external dependency has other dependencies, you will need to call mapDependencies
for each one.
Reference External React Components
If your Activity Pack contains a custom form element that relies upon an external React component, you need to add a call to mapDependencies()
to the configure()
method in src/main.ts
, the same as for other external libraries.
react-circular-color Component.
Example: Using the- Run
npm install react-circular-color
in the terminal. - Follow the instructions above to create and register a new custom form element
ColorPicker.tsx
React component that just returns a single color picker.
- Copy the
react-circular-color
folder from yournode_modules
todist/deps
- Add a call for
react-circular-color
tomapDependencies()
to theconfigure()
method insrc/main.ts
.
Limitations
There are some limitations on the types of component you can load:
- You can only import components that are defined using the AMD or UMD syntax.
- You cannot import components defined using the CommonJS syntax.