Skip to content
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

including in webpack build #8

Open
acthp opened this issue Sep 17, 2015 · 3 comments
Open

including in webpack build #8

acthp opened this issue Sep 17, 2015 · 3 comments

Comments

@acthp
Copy link

acthp commented Sep 17, 2015

Is there a recommended way to include this lib from webpack? Doing a simple require() results in dependencies (d3-tip) not being available at run-time.

@mpschr
Copy link
Contributor

mpschr commented Sep 21, 2015

Hi @acthp

I have never used webpack and don't know what may be causing the problem. Does webpack also use the package.json file to install dependencies?

@acthp
Copy link
Author

acthp commented Sep 21, 2015

Yes, webpack uses npm and require(). The problem is that muts-needle-plot uses a combination of require() , and global variables, with d3, underscore, and d3-svg-legend being loaded as globals, but others being loaded with require(). I eventually worked out a solution using webpack's shims for legacy modules. Like this:

// The next three are required for muts-needle-plot.
{ test: /d3-svg-legend/, loader: "imports?d3=d3" },
{ test: /muts-needle-plot/, loader: "imports?_=underscore" },
// The d3-tip AMD loader does not populate d3.tip, which is expected
// by muts-needle-plot. So, we disable it here. The CommonJS loader
// will populate d3.tip.
{ test: /d3-tip/, loader: "imports?define=>false" },

and also doing an explicit require() for d3-svg-legend. The 'imports' loader injects a binding into a module that is expecting a global variable.

If you don't want to directly require() some dependencies, e.g. so the user can override them, you can parameterize the lib with the dependencies. Like change the globals to parameters on the constructor, or on an 'initialize' routine.

@mpschr
Copy link
Contributor

mpschr commented Sep 22, 2015

Ok, thanks for the info and glad you could manage it, @acthp.

The above line you have added to the package.json? Please feel free to make a fork and add you changes.

Also if you know very well which changes to make to muts-needle-plot I would appreciate a patch since in this moment I don't see time to tackle this issue and it wuold help you clean up the code in your project.

Best

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

No branches or pull requests

2 participants