Skip to content

Conversation

@vamche
Copy link
Contributor

@vamche vamche commented Aug 2, 2021

No description provided.

src/index.ts Outdated
const config: Omit<BuildOptions, 'watch'> = {
...this.buildOptions,
external: [...this.buildOptions.external, ...this.buildOptions.exclude],
external: [...this.buildOptions.external, ...removeWildCardStrings(this.buildOptions.exclude)],
Copy link
Contributor Author

@vamche vamche Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the plugin passes the packages that are included in exclude currently, I tried not to disturb that behavior. But the wild card/patterns don't make any sense to pass, so removing them here, including only the plain strings.

@vamche
Copy link
Contributor Author

vamche commented Aug 3, 2021

@floydspace @olup Could you please review when you have some time?

@vamche
Copy link
Contributor Author

vamche commented Aug 9, 2021

Hello @floydspace, @olup
Did you get a chance to review the PR?

@floydspace
Copy link
Owner

Hi @vamche , I couldn't yet, was Covid-19 positive. Will check the PR this week. Thanks

@vamche
Copy link
Contributor Author

vamche commented Aug 9, 2021

@floydspace Sorry to hear that, hope you are doing OK now. I wish you a speedy recovery 🚀

@floydspace
Copy link
Owner

Hi @vamche , I tested your changes and got a couple of remarks. First I want to clarify how the external and exclude work together:

  1. by default if external and exclude are not set, esbuild will bundle all references in output.
  2. when you list libs in an external option, esbuild will not bundle them but instead will use node_modules packaging logic.
  3. when we use exclude option, esbuild will do the same as in 2. + libs will not be packaged as node_moduels.

what I expect from this PR: the goal is to implement an ability to exclude libs from packaging as node_modules using wildcard pattern. so instead of listing all the libs in exclude, we would set * only (or any other pattern like lod*sh or whatever) and behavior from point 3 should persist. So we should search the libs according to pattern in package.json in packaging logic and do not copy them (exclude) to node_modules.

But what I see now, it uses pattern to search libs in external list, so basically you have to set externals and exclude to have it somehow work. But why to set externals if we exclude them anyway. Something wrong here. I would suggest keep it simple first, like implement * only, it would mean we exclude everything, so node_modules packaging logic is disabled, and if it's clear enough to make more complex logic with patterns, continue with it if it is really necessary.

Thank you.

@vamche vamche force-pushed the feature/support-regex-for-exclude branch from 7f986a5 to a9345c9 Compare August 12, 2021 09:36
@vamche
Copy link
Contributor Author

vamche commented Aug 12, 2021

@floydspace Thanks for the review, it helped me to understand the plugin more.

I've updated the PR, as you suggested, I kept it simple to support only * which should disable node_modules packaging. Could you please review it again?

Usage:

esbuild:
  exclude: "*"

or

esbuild:
  exclude: 
    - "*"

@vamche
Copy link
Contributor Author

vamche commented Aug 22, 2021

@floydspace Could you please review?

@vamche
Copy link
Contributor Author

vamche commented Aug 30, 2021

Hello @floydspace, hope everything is OK on your side. I just wanted to check if you got a chance to review the PR after the changes?

@vamche vamche force-pushed the feature/support-regex-for-exclude branch from a9345c9 to 8c33aa5 Compare September 5, 2021 09:56
@vamche
Copy link
Contributor Author

vamche commented Sep 7, 2021

@floydspace Did you get a chance to look at the PR again?

@vamche vamche added help wanted Extra attention is needed need reviews labels Sep 9, 2021
@vamche vamche requested review from floydspace and removed request for floydspace September 10, 2021 07:33
@vamche
Copy link
Contributor Author

vamche commented Sep 18, 2021

@floydspace could you please give this a look again?

Copy link
Owner

@floydspace floydspace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vamche , sorry that ignored it for a long time, I approve it. I will merge it as a minor fix

external: [...this.buildOptions.external, ...this.buildOptions.exclude],
external: [
...this.buildOptions.external,
...(this.buildOptions.exclude === '*' || this.buildOptions.exclude.includes('*') ? [] : this.buildOptions.exclude)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here if exclude is * we must put all the dependencies as external otherwise they will be bundled which we do not need. in other words, if * it should behave like webpack-node-externals

@floydspace floydspace merged commit 5c75cad into floydspace:master Sep 18, 2021
@github-actions
Copy link

🎉 This PR is included in version 1.18.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ericmaicon
Copy link

ericmaicon commented Jan 26, 2022

hey there,

I am not sure if this is working properly. I setup exclude as the following:

exclude: '*'

check how is the size of my zip file when I run yarn sls package:

image

now I tried to remove all the things I have as dependencies on exclude:

exclude: [
        'pg',
        'reflect-metadata',
        'typeorm',
        'typeorm-naming-strategies',
        'unzipper',
        '@serverless/typescript',
        '@types/aws-lambda',
        '@types/faker',
        '@types/jest',
        '@types/node',
....
]

You can see that I needed to list even my dev dependencies here. After that, this is what I got:

image

The goal wans't to list all of it?!

The versions I am using is the following:

"serverless": "^2.23.0",
    "serverless-esbuild": "^1.23.1",

Thanks in advance.

@AlisonVilela
Copy link

ericmaicon Same here!

wildcard doesn't work, I need to put all the libraries I'm using one by one

@samchungy
Copy link
Collaborator

I'll take a peek over the weekend 👀

@vamche
Copy link
Contributor Author

vamche commented Aug 15, 2022

@ericmaicon @AlisonVilela This implementation requires the node modules to be set as externals as well.

Here is a sample configuration.
serverless.yml

  esbuild:
    plugins: ./esbuild-plugins.js
    exclude: '*'

esbuild-plugins.js

const { nodeExternalsPlugin } = require('esbuild-node-externals');

module.exports = [
  nodeExternalsPlugin(),
];

Please let me know if you have questions. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants