Skip to content

Use plotly.js browser script vs. npm module #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2017

Conversation

gnestor
Copy link
Collaborator

@gnestor gnestor commented Sep 22, 2017

Closes #21

Resolves an issue with bundling plotly.js using webpack: https://github.com/plotly/plotly.js#building-plotlyjs-with-webpack

@gnestor gnestor force-pushed the fix-plotly branch 2 times, most recently from 149eef1 to b2be961 Compare September 26, 2017 06:39
loading = true;
const script = document.createElement('script');
script.type = 'text/javascript';
script.text = require('raw-loader!../vendor/plotly-1.28.3.min.js');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blink1073 Ideally, we could just set script.src to the relative path of the plotly.js file, but unfortunately that won't work once it's all bundled with webpack. Using raw-loader, we can get the content of the plotly.js file and set script.text, but this seems a little hacky... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't even need to vendor the file if you use the raw-loader, you can use raw-loader!plotly/dist/plotly.min.js. I think that this approach is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean raw-load it from a CDN?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as a third party import that webpack will resolve.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't load the script until it is actually needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show me what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script.text = require('!raw-loader!plotly/dist/plotly.min.js'), where plotly/dist/plotly.min.js is the location of the file in node_modules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, I like that better 👍

@gnestor gnestor merged commit 7334a45 into jupyterlab:master Sep 26, 2017
@gnestor gnestor deleted the fix-plotly branch September 26, 2017 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants