Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include node_modules when externals are populated via plugins (for eg., esbuild-node-externals) #136

Closed
vamche opened this issue Jun 10, 2021 · 3 comments · Fixed by #139
Assignees
Labels
enhancement New feature or request

Comments

@vamche
Copy link
Contributor

vamche commented Jun 10, 2021

Kudos to the team which is behind this plugin and the packaging speeds it comes with! 🙇

I have a question (feature-request?) for you. When the below code is packaged, the final deployment does not include the externals (node modules). I think it is because the externals are populated by a plugin in this case esbuild-node-externals.

https://github.com/vamche/sls-esbuild-node-externals/blob/4cc8843ed9c486727d3c3e89dabc1904ae7521ef/plugins.js#L3-L6

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


// default export should be an array of plugins
module.exports = [nodeExternalsPlugin()];

https://github.com/vamche/sls-esbuild-node-externals/blob/4cc8843ed9c486727d3c3e89dabc1904ae7521ef/serverless.yml#L15-L17

  esbuild:
    plugins : ./plugins.js
    packager: npm

Sample repo: https://github.com/vamche/sls-esbuild-node-externals

Is there a way to include node_modules when externals are populated via plugins?

@vamche vamche changed the title Include node_modules when externals are populated via plugins (esbuild-node-externals) Include node_modules when externals are populated via plugins (for eg., esbuild-node-externals) Jun 10, 2021
@vamche
Copy link
Contributor Author

vamche commented Jun 10, 2021

FYI, serverless-webpack does this with includeModules config and webpack-node-externals plugin.

I am happy to help/contribute to code if this feature can be introduced (if not already available). I would need some direction though. :)

@floydspace
Copy link
Owner

Hi @vamche , thank you for the issue and the example. I cloned your repo and indeed the esbuild-node-externals plugin is excluding your dependencies from the bundle, but serverless-esbuild assumes that they are bundled.

I think it makes sense to implement a special case with the plugin, so if it is used we just get the list of modules determined by the plugin and put them to external to have packed.

If you really like to contribute, here is the direction: the plugin has exported function findDependencies you can reuse it to build a list of dependencies to be packed, and then the list must be used in our packExternalModules function which does the job. Should be an easy fix. Thank you 🙏

@vamche
Copy link
Contributor Author

vamche commented Jun 10, 2021

Thank you @floydspace, I will give it a shot.

@floydspace floydspace added the enhancement New feature or request label Jun 10, 2021
floydspace added a commit that referenced this issue Jun 15, 2021
…-with-externals-plugin

feat(external): pack node_modules when esbuild-node-externals is configured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants