Add a library
Include the library manually
Copy yourLibrary.js
to the src/lib/yourLibrary
directory and include yourLibrary.js
in index.html
.
<script type="text/javascript" src="lib/yourLibrary/yourLibrary.js"></script>
Dependency management with dizmoGen
All dizmoGen (sub-)generators support dependency management using Node modules: You can structure your dizmo code using require
, exports
and module.exports
objects. Further, you can install external third party libraries and reference them directly with require. For example, to use jQuery run:
npm install --save jquery
Then in your code you can get a reference with:
var $ = require('jquery');
If you want to remove an installed library just run:
npm remove --save jquery
This approach works well, as long as the external libraries are not too large, since otherwise the build process may take longer. Also, any dependent libraries are included in index.js
. To shorten the build process you can use the incremental builder using the watcher:
npm run watch
Practical example
In a later stage, we will be using the library D3.js
to visualize data in the Gauge dizmo.
Copy d3.js
to the src/lib/d3
directory.
Include d3.js
in index.html
:
<html>
<head>
...
<script type="text/javascript" src="lib/d3/d3.js"></script>
...
<!-- Your own stylesheet (do not remove!)-->
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>
<body>
...