Use Requirejs to add third-party tools or libraries in Oracle JET applications.
Steps:
1. If you use a tool frame scaffold, you need to do it.
A. Use NPM to install the libraries you need.
NPM Install My-library--save
B. In the Script/grunt/config directory, locate the copycustomlibstostaging update code in the Oraclejet-build.js.
Remove the note. and change:
copycustomlibstostaging: { fileList: [ {cwd:' node_modules/my-library/', src: [' * ' ], ' web/js/libs/my-library ' } ]},
C. In the Src/js directory, add a new library to the Main-release-paths.json file. Use the min version. This file is used when building the release.
{ "knockout": "libs/knockout/knockout-x.x.x", "jquery": "Libs/jquery/jquery-x.x.x.min" , ... contents omitted "my-library": "Libs/my-library/my-library.min"}
2. If you are not building using the tool framework, add new libraries and accompanying files directly to the Js/libs directory.
3. After performing the previous step, use Requierjs to add a path to Requirejs.config in Main.js and define it in require if needed.
Requirejs.config ({//add a path to a new librarypaths: {' Knockout ': ' libs/knockout/knockout-3.4.0 ', ' jquery ': ' Libs/jquery/jquery-3.1.0.min ',... contents omitted' Text ': ' Libs/require/text ', ' my-library ': ' libs/my-library/my-library }, //If it is not an AMD module, add the content required for the new library here Shim: {' jquery ': {exports: [' JQuery ', ' $ ']}}, require ([' Ojs/ojcore ', ' knockout ', ' jquery ', 'my-library‘],function(OJ, KO, $)//callback function that executes after all modules have been loaded { //Add use code here });
Oracle JET uses Requirejs third-party tools or libraries to introduce