serverless-esbuild icon indicating copy to clipboard operation
serverless-esbuild copied to clipboard

feat(externals): add option to disable packing of external modules

Open mattjennings opened this issue 4 years ago • 4 comments

Adds an additional configuration option packExternals which will disable installing & bundling modules listed as external.

This is useful for if you want to exclude externals from esbuild but you don't need them installed & packed separately. My use-case was with serverless-offline as externals can be imported normally from node_modules, leading to a faster build. Another use-case could be if you're using lambda layers.

mattjennings avatar Apr 20 '21 20:04 mattjennings

Hi @mattjennings, thank you for your PR.

The package specified in the exclude option is passed to esbuild as external, but it is not included in the function bundle either.

we already have the option exclude, will it cover your use case?

what can we do extra is making exclude option accept boolean values, so if it is true it excludes everything set as external. I have the reason for this: having set exclude and packExternals does not make sense together (exclude would have no effect), so it is why we can keep only one option, but I need second eyes from @olup on it.

floydspace avatar Apr 20 '21 21:04 floydspace

Ah yes, I hadn't considered the exclude option. I agree, finding a way to use exclude is a better idea. A boolean might be fine, otherwise maybe allowing pattern matching or * as a value to designate excluding everything.

mattjennings avatar Apr 20 '21 21:04 mattjennings

maybe allowing pattern matching or * as a value to designate excluding everything

also works for me 👍, please also describe it in the readme if you gonna make the fix.

floydspace avatar Apr 20 '21 21:04 floydspace

@floydspace @mattjennings I've opened https://github.com/floydspace/serverless-esbuild/pull/167 for pattern matching. Could you please give it a look?

vamche avatar Aug 02 '21 10:08 vamche