Adding 3rd party JavaScript libraries
Usually using npm install --save
to add a library and import
it as ES-module is enough and the recommended approach.
However sometimes you might need a more old-school approach that is described below:
Add library files under
[oskari-frontend or your repository]/libraries/<yourLibrary>/
If your library is just for your own bundle
- reference library files in your
bundle.js
- reference library files in your
If your library is for several bundles
- create a new
bundle.js
under[oskari-frontend or your repository]/packages/libraries/<yourLibrary>/
- include this new "library bundle" in the startup sequence of your bundle
- create a new
Example of library bundle.js
:
(function() {
/**
* @class Oskari.libraries.bundle.geostats.GeostatsBundle
*/
Oskari.clazz.define("Oskari.libraries.bundle.geostats.GeostatsBundle", function() {
}, {
"create" : function() {
return this;
},
"update" : function(manager, bundle, bi, info) {},
"start" : function() {},
"stop" : function() {}
}, {
"protocol" : ["Oskari.bundle.Bundle","Oskari.bundle.BundleInstance"],
"source" : {
"scripts" : [{
"type" : "text/javascript",
"src" : "../../../../libraries/geostats/geostats.min.js"
},
{
"type" : "text/javascript",
"src" : "../../../../libraries/geostats/jenks.util.js"
}]
}
});
// Install this bundle by instantating the Bundle Class
Oskari.bundle_manager.installBundleClass("geostats", "Oskari.libraries.bundle.geostats.GeostatsBundle");
})();
Last modified: Fri Mar 31 2023 13:15:51 GMT+0300 (Eastern European Summer Time)