-
Notifications
You must be signed in to change notification settings - Fork 298
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
feat: dynamic rollup configuration for esm flattening #395
feat: dynamic rollup configuration for esm flattening #395
Conversation
src/lib/steps/rollup.ts
Outdated
...opts.externals, | ||
const embedded: string[] = opts.embedded || []; | ||
const namedExternals = { | ||
'tslib': 'tslib', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might also make sense to add some other defaults that are widely used example, ionic-angular
, lodash
, moment
, date-fns
, react
etc..
Need to update lockfile, though I am on my mobile at the moment! |
src/lib/steps/rollup.ts
Outdated
embedded.some(x => x === moduleId) | ||
) { | ||
// if it's either 'absolute', marked to embed, starts with a '.' or '/' it's not external | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of extracting to a function / lambda?
const externalModuleIdStrategy = (moduleId: string): boolean => {
/* ... */
}
Then write a unit test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d love that, if you tell me where to place the unit test etc... :) I’d find it much more easy to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small correction from your example, to test it, you need to export it though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes! 😄
src/lib/steps/rollup.ts
Outdated
} | ||
|
||
return namedExternals[moduleId] || ''; // leave it up to rollup to guess the global name | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. Extract to a function / named lambda and then write a unit test for that piece of functionality?
const umdModuleIdStrategy = (moduleId: string): string => { /* ... */ }
/* ... */
describe(`umdModuleIdStrategy`, () => {
it(`should map rxjs/add/operator/<foo> to Rx.Observable.<foo>`, () => {
/* ... */
});
});
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree.
Thanks, will do that. |
From rollup's API docs:
Let's rename |
src/lib/steps/rollup.spec.ts
Outdated
expect(umdModuleIdStrategy('foo')).to.empty; | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
integration/samples/rollup/README.md
Outdated
@@ -0,0 +1,2 @@ | |||
Sample library: external and embeded dependencies | |||
===================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think we can move this integration test to integration/samples/external
@alan-agius4 When you make these two little adjustments, I think it's good to go! |
BREAKING CHANGE: `externals` has been removed in favor of `umdModuleIds` which is now only used to name the external libraries. By default all dependencies are now treated as externals and thus are not embedded in the final bundle. However, If you want to embed one or more of them into the final bundle you can do so by adding the library in the `embeeded` section like so; ```json { "$schema": "../../../src/ng-package.schema.json", "lib": { "embedded": [ "lodash", "date-fns" ] } } ``` While `rollup` will do it's best to guess the name of an external library some modules are hard to guess and it's recommended to provide the name of the external dependency. This can be done by using `umdModuleIds` in the config section like so; ```json { "$schema": "../../../src/ng-package.schema.json", "lib": { "umdModuleIds": { "lodash" : "_", "date-fns" : "DateFns", } } } ``` Closes: #312
@dherges updated as requested. |
@alan-agius4 perfect! |
Just added a few words to the readme, hoping to clarify and be precise on the terms "externals", "dependency", "bundle", and so on |
Thank you Alan, this is a good step to the right direction! |
Glad to help :) |
This PR has been automatically locked due to inactivity. |
I'm submitting a...
Checklist
Description
externals
has been removed in favor ofumdModuleIds
which is now used to just provide the UMD module IDs of external libraries (in case they cannot be auto-guessed by rollup; see further below).By default all dependencies are now treated as externals and thus are not embedded in the final bundle.
However, if you want to embed one or more of them into the final bundle you can do so by adding the external dependency in the
embedded
section like so:While
rollup
will do it's best to guess the UMD module ID of an external dependency (and ng-packagr provides common defaults for angular and rxjs) some modules are hard to guess and it's recommended to provide the name of the external dependency. This can be done by usingumdModuleIds
in the config section like so:A migration example can be found in ab52732
Does this PR introduce a breaking change?
Closes: #312