Closed riskers closed 7 years ago
Sorry for the late reply. Is there require('jquery')
inside your library. If yes, then this result is correct.
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
@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.
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!
Oh, solution found
modules: [path.resolve('./src'), path.join(__dirname, 'node_modules')],
@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.
I resolved my issue by adding the following into the config object:
target: 'node'
a good read from jlongster blog
@riskers do we have to keep the issue open?
Now, I have a library
xx
dependingjQuery
:I find #3 , so I write this externals:
It's great! The bundle file is small!
But, when I use my library:
then use webpack, the library put
xx
andjQuery
together. I don't know how to separate them?