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

Improve lodash imports to reduce size of serverless bundles #298

Merged
merged 1 commit into from
Apr 9, 2019

Conversation

luisherranz
Copy link
Contributor

Summary

Serverless is becoming popular and bundle size is important. This PR avoids importing the whole lodash code, even in the server.

Test plan

Tests pass for ChunkExtractor.js, the only affected file.

@gregberge
Copy link
Owner

I like that, thanks @luisherranz!

@luisherranz
Copy link
Contributor Author

That was fast. Thanks @neoziro! :)

@bitttttten
Copy link
Contributor

bitttttten commented Apr 17, 2019

I am not sure what this fixed for you @luisherranz because serverless will still install and include the entire lodash library inside the lambda since the dependencies inside @loadable/server's package.json didn't change.

Wouldn't you want to remove lodash, and install lodash.uniq, lodash.uniqBy and lodash.flatMap? Maybe I am missing something :)

@luisherranz
Copy link
Contributor Author

@bitttttten it works if you build your bundle using webpack or ncc but I agree that maybe adding them as packages may cover more cases.

@bitttttten
Copy link
Contributor

Ohh I see. I am not using webpack to bundle my lambdas! To be honest I didn't ever think of doing that. I guess that answers my question, thanks!

If you bundle your lambda with webpack, then wouldn't you loose all the niceties of the console editor? Or does it some how keep all that?

@luisherranz
Copy link
Contributor Author

I'm not familiar with AWS because I use other service. If code don't need to be bundled, then maybe it's not a good idea to make it necessary if someone is using loadable component.

Could you please describe what is the normal workflow in AWS?

@ScriptedAlchemy
Copy link

use webpack alias to resolve dependencies

@theKashey
Copy link
Collaborator

use webpack externals to keep node_modules in node_modules

@ScriptedAlchemy
Copy link

Can you run require on a lambda? And require node modules on that side?

@theKashey
Copy link
Collaborator

Of course, you can. Majority of lambdas(they were not created just for SSR task) are written in pure nodejs, and haven't ever experienced any bundler.

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

Successfully merging this pull request may close these issues.

5 participants