serverless-webpack icon indicating copy to clipboard operation
serverless-webpack copied to clipboard

Add hint about using yarn for smaller packages in the documentation

Open khaledosman opened this issue 6 years ago • 0 comments

This is a (Bug Report / Feature Proposal)

Feature Proposal for README / documentation

Description

I was able to cut my package sizes by more than half and increase the packaging & deployment speed by switching from npm to yarn and using yarn's autoclean command in combination of packagerOptions.scripts and node-externals

This is my serverless-webpack config

  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
    forceExclude:
      - aws-sdk
    packager: "yarn"
    packagerOptions:
      scripts:
        - yarn autoclean --init
        - cat ../../.yarnclean >> .yarnclean
        - rm -rf node_modules/aws-sdk
        - yarn autoclean --force

Here I copy my root project's .yarnclean file to each package's and I manually remove aws-sdk since it was still being included in my package through aws-xray-sdk in my case which lists it as an npm dependency.

And this is my .yarnclean file which is a combination of the autogenerated yarnclean file by running yarn autoclean --init and the files listed by node-prune which helped me reduce the size of my included node_modules dramatically. https://gist.github.com/khaledosman/e145fffc2de691e780c7da246e2b3da4

Additional Data

I think one of the main pain points of using this plugin is the package size as well as packaging & deployment speed.

Adding a hint in the readme about using yarn as a packager with autoclean with a configuration like the above would be benificial to alot of people.

Doing this I managed to cutdown my deployment package size from one of my lambdas from 18MB down to 7.2MB and others from 11MB to 2.7MB

khaledosman avatar Jan 24 '20 14:01 khaledosman