-
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
Reduce bundle size by removing unnecessary files from node_modules #519
Comments
Hi @mcongy , did you try
The scripts option is made especially to execute vustom scripts after installation of the node modules |
Hi @HyperBrain Sorry for reacting so late. I didn't realize I can specify post-installation script. It could work very well. Do you have an idea, what would be the best solution to doing this? Thanks! |
This worked for me: webpack:
webpackConfig: "webpack.config.js"
packager: "yarn"
packagerOptions:
scripts:
- yarn autoclean --init
- yarn autoclean --force
includeModules: true
|
if you still have problems with your package size try this out: I was able to reduce my packaged zip files sizes almost by more than half by using yarn clean for the included node modules and having a more strict .yarnclean config. This config is a combination of the default .yarnclean file created via then in serverless.yml I use the root .yarnclean file for the included node_modules webpack:
webpackConfig: ./webpack.config.js
includeModules: true
forceExclude:
- aws-sdk
packager: "yarn"
packagerOptions:
scripts:
- yarn autoclean --init
- rm .yarnclean && cat ../../.yarnclean >> .yarnclean && echo '\n*.ts' >> .yarnclean
- rm -rf node_modules/aws-sdk
- yarn autoclean --force Then I forcefully remove aws-sdk from the package since it was still being included indirectly via aws-xray-sdk which states it as a dependency in package.json increasing my package size dramatically. |
Any solutions for |
This is a Feature Proposal
Description
node_modules include a lot of unnecessary files (license files, test files, CI/CD config files, build config files etc.).
These files are absolutely useless and are not needed at runtime.
They increase the bundle size, the time it takes to zip bundles and upload them to S3.
We can save a significant amount of time (and even money to some degree) by removing them.
Yarn has a functionality called "autoclean". It removes files specified by a glob pattern from node_modules https://yarnpkg.com/en/docs/cli/autoclean
We could use yarn's autoclean funcionality or remove the unnecessary files ourselves.
I think this should be a configurable option.
Maybe we could allow executing an "autoclean" script after packager install it's depencencies? Maybe here?
serverless-webpack/lib/packExternalModules.js
Lines 329 to 332 in 2139384
Maybe something like this?
The text was updated successfully, but these errors were encountered: