You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone, and first of all, thanks for the hard work you're putting in this project !
Feature Request's related problem
I need to be able to exclude ALL node_modules from the build/deploy result .zip file, in order to keep functions as lightweight as possible (less than 1mb) while using npm libraries like pg for database queries among others, with any of those being around 500kb each, at least.
My solution is to put them into an AWS Layer containing all my runtime dependencies, so any function would only contain the code it needs, but there is no way to exclude them properly, as far as I know.
Combined with the fact that every function's build contains all the service's functions without being able to build every function truly independently as already mentioned #81 and the other fact that when I use one of my /libs the whole library is included even with the import { A, B, C } from '@project/lib' syntax, my functions are becoming more and more bulky with time, even a 5 lines function.
The problem with /libs is for another issue, so my focus here is about excluding ALL npm dependencies if needed, not just devDependencies.
Desired Solution
Either an option for builders/executors with a list of glob patterns to forceExclude so one could write something like node_modules/*, but the most straightforward and most simple option would be a property in serverless.yml or an option for builder/executor to exclude all dependencies, including runtime.
This would need to be explicit as this behaviour in serverless-webpack is to prevent runtime errors, but as a grown person, one could take their own risks if they explicitly ask for it, with maybe a warning during the build to prevent about the possible issues, just in case.
In order for the function in Lambda to recognise the libraries like casual node_modules directly from the layer, maybe it must be included in the function's package.json, meaning this option for excluding all dependencies would mean no yarn install, or just avoiding the node_modules while zipping.
Considered Alternatives
Tried to put all my dependencies as devDependencies but I get this error from serverless-webpack
ERROR: Runtime dependency 'pg' found in devDependencies. Move it to dependencies or use forceExclude to explicitly exclude it.
By trying to forceExclude as recommended by serverless-webpack, my runtime dependencies are silently included in the final build anyway. Even if it worked as expected, one should write every module I use explicitly for every service, which would be a real pain in the a**.
Affected Providers :
[X] AWS
[?] Azure
[?] Google Cloud Platform
Affected Frameworks :
[?] Angular
[?] Nodejs
[X] Serverless
[X] Lambda
[?] Infrastructure as a code
Additional Context
This option would probably cause problems with serverless-offline as it is based on the same build target. If this hypothetical option (an excludeNodeModules boolean for this example) is put in the build target options, it would be possible to base the serve and deploy on different build configurations :
AtlasRW
changed the title
[FEAT] Exclude ALL dependencies from build
[FEAT] Exclude ALL dependencies / node_modules from build
Mar 14, 2022
AtlasRW
changed the title
[FEAT] Exclude ALL dependencies / node_modules from build
[FEAT] Nx-Serverless | forceExclude ALL dependencies from build
Mar 14, 2022
AtlasRW
changed the title
[FEAT] Nx-Serverless | forceExclude ALL dependencies from build
[FEAT] Nx-Serverless | option to exclude ALL dependencies from build
Mar 14, 2022
Hi everyone, and first of all, thanks for the hard work you're putting in this project !
Feature Request's related problem
I need to be able to exclude ALL node_modules from the build/deploy result
.zip
file, in order to keep functions as lightweight as possible (less than 1mb) while usingnpm
libraries likepg
for database queries among others, with any of those being around 500kb each, at least.My solution is to put them into an AWS Layer containing all my runtime dependencies, so any function would only contain the code it needs, but there is no way to exclude them properly, as far as I know.
Combined with the fact that every function's build contains all the service's functions without being able to build every function truly independently as already mentioned #81 and the other fact that when I use one of my
/libs
the whole library is included even with theimport { A, B, C } from '@project/lib'
syntax, my functions are becoming more and more bulky with time, even a 5 lines function.The problem with
/libs
is for another issue, so my focus here is about excluding ALLnpm
dependencies if needed, not just devDependencies.Desired Solution
Either an option for builders/executors with a list of glob patterns to
forceExclude
so one could write something likenode_modules/*
, but the most straightforward and most simple option would be a property inserverless.yml
or an option for builder/executor to exclude all dependencies, including runtime.This would need to be explicit as this behaviour in
serverless-webpack
is to prevent runtime errors, but as a grown person, one could take their own risks if they explicitly ask for it, with maybe a warning during the build to prevent about the possible issues, just in case.In order for the function in Lambda to recognise the libraries like casual
node_modules
directly from the layer, maybe it must be included in the function'spackage.json
, meaning this option for excluding all dependencies would mean noyarn install
, or just avoiding thenode_modules
while zipping.Considered Alternatives
serverless-webpack
forceExclude
as recommended byserverless-webpack
, my runtime dependencies are silently included in the final build anyway. Even if it worked as expected, one should write every module I use explicitly for every service, which would be a real pain in the a**.Affected Providers :
[X] AWS
[?] Azure
[?] Google Cloud Platform
Affected Frameworks :
[?] Angular
[?] Nodejs
[X] Serverless
[X] Lambda
[?] Infrastructure as a code
Additional Context
This option would probably cause problems with
serverless-offline
as it is based on the samebuild
target. If this hypothetical option (anexcludeNodeModules
boolean for this example) is put in thebuild
target options, it would be possible to base theserve
anddeploy
on differentbuild
configurations :The text was updated successfully, but these errors were encountered: