-
Notifications
You must be signed in to change notification settings - Fork 417
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
package: individually: true generates huge files when using the same handler file for multiple functions #195
Comments
Deploying functions individually seems to work fine though. package:
individually: false
|
It seems there's something special with the first 2 functions. Can you post the compile output for individual packaging for the 3 functions (webpack should in this case compile all 3 functions separately)? Can you do a We use it in multiple of our projects here and never encountered such a strange behavior - with and without individual packaging (the difference is, that we use node-externals to handle the externals for the webpack compile). Node-externals let's you also define a whitelist for external modules that you want to compile into your code. |
Output of
The If I then unpack the three zip files, the small one only has We're not using |
Running |
|
I've put together a repo for you to try out. https://github.com/metocean/test-webpack-individually
If you unpack the zip files in |
I had a colleague test that repo as well, same issue. He's running Mac. |
@msl-kabo Thanks for the detailed input. I will check out the sample repo and try to find out why it did this strange packaging. I remember to have seen a similar issue in the past where something was wrong in the configuration. I'll let you know as soon as I have analyzed it. |
@msl-kabo I reproduced the issue. It seems that the multi compile got broken by one of the last commits (or the merge). The error is, that the plugin does not compile the 3 functions individually anymore and Serverless packages the last two (which is completely crappy). It seems to happen when multiple functions are different exports of the same handler file. If the handlers are separated into different files, it works. For testing I just duplicated the handler file and referenced a different one from each function definition. This leads to the correct multi-compile:
This proves that the bug is limited to the case when more than one function is exported by the same file. The output zip files are all of the same size now (which is a consequence of using node-externals here and not packaging the libraries themselves). This is ok for the sample project setup:
I will add the modules to node-external's whitelist as soon as the bug is fixed and run the test again. Then the zip sizes should be different according to the specific functions used out of the modules. |
@msl-kabo I will fix the wrong packaging issue, but I see a general flaw in the layout of the project. The benefit from Webpacks optimization is only usable, if you separate the handler layer from the business logic, i.e. you should create 3 handlers for the functions that call the specific export from the lib files. Then Webpack will analyze each handler separately and only use the code used by each specific handler that is accessed from the handlers. Sample: # serverless.yml
functions:
funcA:
handler: handlers/funcA.handler
funcB:
handler: handlers/funcB.handler
funcC:
handler: handlers/funcC.handler File system:
The handlers now export a handler function and each handler calls into lib/handler.functionX. |
It is fixed in the attached PR, but consider changing the project layout as mentioned above ;-) |
Thanks, I hadn't thought about the project layout, great feedback. |
I know this is an old issue, but I've been trying to find details on how to resolve the warning that @msl-kabo had in his output here. I'm getting the same thing, and was wondering if you were able to resolve it?
Ignoring the warning seems to work fine, but I'm wondering what it means. A google search turned up some similar issues, but nothing related to this plugin (though I'm not sure it's related to this plugin either). Using Any thoughts appreciated! |
@itslittlejohn This warning, emitted by webpack, means that Webpack cannot determine a dependency, because somewhere in the code there is a dynamic require, i.e. a call to |
Thanks! Makes sense. I'll just continue to ignore it for now. |
This is a Bug Report
Description
For bug reports:
I ran
serverless deploy -s test
and checked the code size of the functions in the lambda console. The size had gone up from 326.9 kB to 36.4MB.The size to go down, and differ between the packages
serverless.yml
webpack.config.js
Additional Data
My
serverless.yml
has 3 functions, all in the same file,handler.js
.The text was updated successfully, but these errors were encountered: