serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ForceExclude

colinfindlay-nz opened this issue · comments

This is a Feature Proposal

Description

Under the current method for bundling externals, while you can exclude dependencies by marking them as devDependencies, if a downstream dependency re-includes it, it will be bundled regardless.

While 99% of the time this makes sense, there are still a lot of projects out there, that are not lambda exclusive, which include aws-sdk as a dependency. While I could ask every project maintainer to move aws-sdk to peerDependency or devDependency - I think adding a forceExclude would be a simple fix for a wide(ish) problem

i.e.

webpackIncludeModules:
    forceInclude:
      - module1
      - module2
    forceExclude:
      - aws-sdk
      - module2

Hi @silver2k . Thanks for the good idea 🙌 .
Indeed, it would perfectly complement the forceInclude option.

@silver2k Can you try with the PR I opened, if that works correctly on your platform? I did some tests locally and it seems to work. Use "serverless-webpack": "serverless-heaven/serverless-webpack#force-exclude to test.

@silver2k Any chance that you can run some tests? I don't want to merge it only tested by me ;-)

No, I did not. The only difference between 3.1.0 and 3.1.1 is, that the package-lock.json is honored correctly and sets all installed dependencies fixed, if a lock file is available.
Regarding the dependency drops, it would be great if you'd check the packaged package.json file included in the zip files, to see if these are ok.

Packaged package.json between 3.1.0 & 3.1.1 are identical.
Raised #251

hi @HyperBrain ,

this feature doesn't seem works for me

`plugins:

  • serverless-webpack
    custom:
    webpack:
    includeModules:
    forceInclude:
    - "alexa-sdk"
    forceExclude:
    - "aws-sdk"`

In above config, I have aws-sdk is the dependencies of alexa-sdk. I want to exclude aws-sdk in the package out however it still included.

Could you please advise me the best way to exclude aws-sdk .

I am using "serverless-webpack": "^5.1.5",

Thanks

Hi @samuraitruong . This is related to #306 . As long as the aws-sdk is not a peer dependency of alexa-sdk but a real dependency it will be packaged.

However, you can try to actually bundle the alexa-sdk - then the aws-sdk will become a first level dependency and the forceExclude could work.

// webpack.config.js

externals: [ nodeExternals( { whitelist: [ "alexa-sdk" ] } ) ],

and then without the forceInclude

forceExclude:
  - aws-sdk

Can you try that?