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

external dependencies #9

Closed
riskers opened this issue Dec 13, 2016 · 8 comments
Closed

external dependencies #9

riskers opened this issue Dec 13, 2016 · 8 comments

Comments

@riskers
Copy link

riskers commented Dec 13, 2016

Now, I have a library xx depending jQuery:

import $ from 'jquery'

...

I find #3 , so I write this externals:

externals: {
    'jquery': 'jQuery'
}

It's great! The bundle file is small!

But, when I use my library:

var xx = require('xx')

then use webpack, the library put xx and jQuery together. I don't know how to separate them?

@krasimir
Copy link
Owner

Sorry for the late reply. Is there require('jquery') inside your library. If yes, then this result is correct.

@adamkleingit
Copy link

So the library will be bundled together with all its dependencies?
For example if I have import 'angular' then angular will be bundled with my library?
Is there a way to bypass this?

Thanks

@krasimir
Copy link
Owner

@adamkleingit the proper way for handling this case is webpack's externals.

@riskers Now, when I'm reading your question again I think I understood what's going on. Correct me if I'm wrong but you build your library using webpack and then you have a build step (again using webpack) that uses your library. If that's the case then you'll have to use externals option one more time in your build process.

@gen4sp
Copy link

gen4sp commented Mar 1, 2017

But how to include dependencies into your library?
If I use something like import _ from "lodash" it generate an error while building
Module not found: Error: Can't resolve 'lodash' in...
Once I include lodash in externals option it builds perfectly, but library needs lodash as dependency.
Thanks!

@gen4sp
Copy link

gen4sp commented Mar 1, 2017

Oh, solution found
modules: [path.resolve('./src'), path.join(__dirname, 'node_modules')],

@freeman29
Copy link

@gen4sp I've tried your solution above on including dependencies but it's not working correctly because it's now looking for all its dependencies.

I'm trying to include request library.

@freeman29
Copy link

I resolved my issue by adding the following into the config object:

target: 'node'

a good read from jlongster blog

@krasimir
Copy link
Owner

krasimir commented Apr 1, 2017

@riskers do we have to keep the issue open?

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

5 participants