To build the library from source, clone the project from github
To build the library from source, clone the project from github
@ -131,7 +127,7 @@ To build the library from source, clone the project from github
$ git clone git://github.com/almende/vis.git
$ git clone git://github.com/almende/vis.git
The source code uses the module style of node (require and module.exports) to
The source code uses the module style of node (require and module.exports) to
organize dependencies. To install all dependencies and build the library,
organize dependencies. To install all dependencies and build the library,
run `npm install` in the root of the project.
run `npm install` in the root of the project.
$ cd vis
$ cd vis
@ -146,32 +142,30 @@ To automatically rebuild on changes in the source files, once can use
$ npm run watch
$ npm run watch
This will both build and minify the library on changes. Minifying is relatively
This will both build and minify the library on changes. Minifying is relatively
slow, so when only the non-minified library is needed, one can use the
slow, so when only the non-minified library is needed, one can use the
`watch-dev` script instead:
`watch-dev` script instead:
$ npm run watch-dev
$ npm run watch-dev
## Custom builds
## Custom builds
The folder `dist` contains bundled versions of vis.js for direct use in the browser. These bundles contain all the visualizations and include external dependencies such as hammer.js and moment.js.
The folder `dist` contains bundled versions of vis.js for direct use in the browser. These bundles contain all the visualizations and include external dependencies such as *hammer.js* and *moment.js*.
The source code of vis.js consists of commonjs modules, which makes it possible to create custom bundles using tools like [Browserify](http://browserify.org/) or [Webpack](http://webpack.github.io/). This can be bundling just one visualization like the Timeline, or bundling vis.js as part of your own browserified web application.
The source code of vis.js consists of commonjs modules, which makes it possible to create custom bundles using tools like [Browserify](http://browserify.org/) or [Webpack](http://webpack.github.io/). This can be bundling just one visualization like the Timeline, or bundling vis.js as part of your own browserified web application.
*Note that hammer.js version 2 is required as of v4.*
*Note that hammer.js version 2 is required as of v4.*
#### Prerequisites
### Prerequisites
Before you can do a build:
Before you can do a build:
- Install node.js and npm on your system: https://nodejs.org/
- Install *node.js* and *npm* on your system: https://nodejs.org/
- Install the following modules using npm: `browserify`, `babelify`, and `uglify-js`:
- Install the following modules using npm: `browserify`, `babelify`, and `uglify-js`:
Then create a custom bundle using browserify, like:
Then create a custom bundle using browserify, like:
$ browserify custom.js -t babelify -o vis-custom.js -s vis
$ browserify custom.js -t babelify -o dist/vis-custom.js -s vis
This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis` containing only `DataSet` and `Timeline`. The generated bundle can be minified using uglifyjs:
This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis` containing only `DataSet` and `Timeline`. The generated bundle can be minified using uglifyjs:
@ -219,13 +215,13 @@ The custom bundle can now be loaded like:
#### Example 2: Exclude external libraries
#### Example 2: Exclude external libraries
The default bundle `vis.js` is standalone and includes external dependencies such as hammer.js and moment.js. When these libraries are already loaded by the application, vis.js does not need to include these dependencies itself too. To build a custom bundle of vis.js excluding moment.js and hammer.js, run browserify in the root of the project:
The default bundle `vis.js` is standalone and includes external dependencies such as *hammer.js* and *moment.js*. When these libraries are already loaded by the application, vis.js does not need to include these dependencies itself too. To build a custom bundle of vis.js excluding *moment.js* and *hammer.js*, run browserify in the root of the project:
$ browserify index.js -t babelify -o vis-custom.js -s vis -x moment -x hammerjs
This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis`, and has moment and hammerjs excluded. The generated bundle can be minified with uglifyjs:
$ browserify index.js -t babelify -o dist/vis-custom.js -s vis -x moment -x hammerjs
$ uglifyjs vis-custom.js -o vis-custom.min.js
This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis`, and has *moment.js* and *hammer.js* excluded. The generated bundle can be minified with uglifyjs: