background

The project uses third-party plugins that rely on jquery and are written in the UMD specification to implement custom functionality.

Train of thought

Implement global variables by adding properties to the window object.

implementation

1. Jquery can be installed via NPM, and can be imported into the current project using import statements.

2. Open the startup module app. TSX and add the following code to it to set it as a global variable:

import * as jq from 'jquery';  
declare var window: any; 
window.jQuery = jq; 
window.$ = jq; 
Copy the code

3. In the index. HTML file, load the third-party library. You can use the plug-in in a page useEffect.

window.onload = function() {
    var demoelement = document.createElement("script");
    demoelement.src = "%PUBLIC_URL%/demo.js";
    document.body.appendChild(demoelement);
}
Copy the code

reference

Segmentfault.com/a/119000002…

Blog.csdn.net/u010565037/…