Skip to content

Commit b5de241

Browse files
authored
Merge pull request #2654 from plotly/building-instructions
Add Building.md
2 parents 89aa364 + b8e1bea commit b5de241

File tree

3 files changed

+82
-17
lines changed

3 files changed

+82
-17
lines changed

BUILDING.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Building plotly.js
2+
3+
## Webpack
4+
5+
For plotly.js to build with Webpack you will need to install [ify-loader@v1.1.0+](https://github.com/hughsk/ify-loader) and add it to your `webpack.config.json`. This adds Browserify transform compatibility to Webpack which is necessary for some plotly.js dependencies.
6+
7+
A repo that demonstrates how to build plotly.js with Webpack can be found [here](https://github.com/plotly/plotly-webpack). In short add `ify-loader` to the `module` section in your `webpack.config.js`:
8+
9+
```js
10+
...
11+
module: {
12+
rules: [
13+
{
14+
test: /\.js$/,
15+
loader: 'ify-loader'
16+
}
17+
]
18+
},
19+
...
20+
```
21+
22+
## Browserify
23+
24+
Given source file:
25+
26+
```js
27+
// file: index.js
28+
29+
var Plotly = require('plotly.js');
30+
31+
// ....
32+
```
33+
34+
then simply run,
35+
36+
37+
```
38+
browserify index.js > bundle.js
39+
```
40+
41+
to trim meta information (and thus save a few bytes), run:
42+
43+
44+
```
45+
browserify -t path/to/plotly.js/tasks/util/compress_attributes.js index.js > bundle.js
46+
```
47+
48+
## Angular CLI
49+
50+
Currently Angular CLI uses Webpack under the hood to bundle and build your Angular application.
51+
Sadly it doesn't allow you to override its Webpack config in order to add the plugin mentioned in the [Webpack](#webpack) section.
52+
Without this plugin your build will fail when it tries to build glslify for WebGL plots.
53+
54+
Currently 2 solutions exists to circumvent this issue:
55+
56+
1) If you need to use WebGL plots, you can create a Webpack config from your Angular CLI project with [ng eject](https://github.com/angular/angular-cli/wiki/eject). This will allow you to follow the instructions regarding Webpack.
57+
2) If you don't need to use WebGL plots, you can make a custom build containing only the required modules for your plots. The clean way to do it with Angular CLI is not the method described in the [Modules](https://github.com/plotly/plotly.js/blob/master/README.md#modules) section of the README but the following:
58+
59+
```typescript
60+
// in the Component you want to create a graph
61+
import * as Plotly from 'plotly.js';
62+
```
63+
64+
```json
65+
// in src/tsconfig.app.json
66+
// List here the modules you want to import
67+
// this example is for scatter plots
68+
{
69+
"compilerOptions": {
70+
"paths": {
71+
"plotly.js": [
72+
"../node_modules/plotly.js/lib/core.js",
73+
"../node_modules/plotly.js/lib/scatter.js"
74+
]
75+
}
76+
}
77+
}
78+
```

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and more.
2020

2121
* [Quick start options](#quick-start-options)
2222
* [Modules](#modules)
23+
* [Building plotly.js](#building-plotlyjs)
2324
* [Bugs and feature requests](#bugs-and-feature-requests)
2425
* [Documentation](#documentation)
2526
* [Contributing](#contributing)
@@ -103,24 +104,9 @@ Important: the plotly.js code base contains some non-ascii characters. Therefore
103104
<script src="my-plotly-bundle.js" charset="utf-8"></script>
104105
```
105106

107+
## Building plotly.js
106108

107-
#### Building plotly.js with Webpack
108-
109-
For plotly.js to build with Webpack you will need to install [ify-loader@v1.1.0+](https://github.com/hughsk/ify-loader) and add it to your `webpack.config.json`. This adds Browserify transform compatibility to Webpack which is necessary for some plotly.js dependencies.
110-
111-
A repo that demonstrates how to build plotly.js with Webpack can be found [here](https://github.com/rreusser/plotly-webpack). In short add `ify-loader` to the `module` section in your `webpack.config.js`:
112-
```js
113-
...
114-
module: {
115-
rules: [
116-
{
117-
test: /\.js$/,
118-
loader: 'ify-loader'
119-
}
120-
]
121-
},
122-
...
123-
```
109+
Building instructions using `webpack`, `browserify` and other build frameworks are in [`BUILDING.md`](https://github.com/plotly/plotly.js/blob/master/BUILDING.md)
124110

125111
## Bugs and feature requests
126112

tasks/test_syntax.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function assertFileNames() {
205205
base === 'CONTRIBUTING.md' ||
206206
base === 'CHANGELOG.md' ||
207207
base === 'SECURITY.md' ||
208+
base === 'BUILDING.md' ||
208209
file.indexOf('mathjax') !== -1
209210
) return;
210211

0 commit comments

Comments
 (0)