Closed tommueller closed 7 years ago
I was able to fix this by adding lodash as external and global to the rollup.config.js. But shouldn't rollup check by itself that these functions are used and bundle them into the package?
Rollup doesn't do that, you have to specify them yourself, so that it can understand them. That's why those sections are part of the custom configuration now.
I thought rollup does treeshaking? At least it says so here: https://rollupjs.org/
@tommueller sorry I'm so tardy on responding to this--Rollup does do treeshaking, but you have to specify your external libraries. The whole reason we're using Rollup now is so that 3rd party dependencies (such as Lodash) aren't bundled into your library's code. When you specify external
& globals
you're letting Rollup know that it can shake this code out of the bundle and, where it's references, use the alias specified in globals
.
So if you did:
import { map } from 'lodash';
And specified in your custom Rollup config:
{
external: [ 'lodash'],
globals: { 'lodash': '_' }
}
Rollup would know that where every an import ... from 'lodash';
happens that it can use a variable of _
in its place. Hope this makes sense and/or you got past your problem.
Thanks Matt, I already got this working. Thanks for the clarification though!
I use a couple of lodash functions in my library, which is not working in the consuming angular-cli project. I get
undefined is not a function
in all the places where lodash-functions are used.During the build of the angular-librarian project I get a lot of these warnings:
lodash is declared as dependency in the package.json and serving the project works fine. lodash is also installed in the consuming project.
This was working before, so I think it might be an migration issue, but I am not sure ;)