floydspace / serverless-esbuild

💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
MIT License
445 stars 138 forks source link

Different package rules for offline vs deploy? #304

Open joshstrange opened 2 years ago

joshstrange commented 2 years ago

Is your feature request related to a problem? Please describe. I'm running into an issue where the package->pattern rules are being followed for serverless-offline AND for deploys. Previously (when using webpack) the package patterns were only used for the deploy. I can see the value in having local builds mimic actual deploys but the issue is I need to include 1 file when running in offline mode and a different file when deploying to lambda.

My issue is with prisma engines. Prisma has different engines for different arch's and with lambda size limits I don't want to include both my local engine and the engine that lambda needs (they are large, like 50mb each).

Here is the patterns list I wish to use:

            'node_modules/.prisma/client/**',
            '!node_modules/.prisma/client/libquery_engine-*',
            'node_modules/.prisma/client/libquery_engine-rhel-*',
            '!node_modules/prisma/libquery_engine-*',
            '!node_modules/@prisma/engines/**',

As it stands now I have to add in darwin to use sls offline but I don't want to deploy that engine.

            'node_modules/.prisma/client/**',
            '!node_modules/.prisma/client/libquery_engine-*',
            'node_modules/.prisma/client/libquery_engine-rhel-*',
            'node_modules/.prisma/client/libquery_engine-darwin-*', // Added
            '!node_modules/prisma/libquery_engine-*',
            '!node_modules/@prisma/engines/**',

Describe the solution you'd like Some way to include/exclude (or use patterns) files based on offline vs deploy.

Describe alternatives you've considered I've considered just manually commenting/uncommenting the rules I need or even scripting something so that my github actions will make sure to deploy the correct files but I still want to be able to deploy from my laptop if needed and I worry I won't always remember to flip the include/exclude.

Additional context I'm 50% sure I'm missing something basic and/or there is a way to accomplish what I want that I'm just not seeing. Any help would be greatly appreciated. I just switched to esbuild + serverless-esbuild today after previously using webpack. esbuild has been a god-send for being able to package individually (webpack took forever, like over 10 min+ before I gave up and eslint does it in under a minute) so that I can keep my lambda size down. Thank you for this plugin, it's been very helpful.

samchungy commented 2 years ago

Yeah I can't see us implementing something this specific just for Serverless Offline. Ideally the Serverless Offline environment should match the Prod environment as closely as possible.

You could probably do something like this with the custom section or with the new Params feature from Serverless v3. https://www.serverless.com/framework/docs/guides/parameters https://github.com/DataDog/serverless-plugin-datadog#disable-plugin-for-particular-environment

joshstrange commented 2 years ago

I’ll look into both and report back if I find a good way to handle it (for other people who might be in the same position). I totally understand your stance, I just would prefer to avoid adding 50MB to each of my individually packaged functions (because I have both the lambda and Darwin engines in the package). Thank you!