serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 417 forks source link

Transpile/transform additional files that are dynamically required at runtime #428

Open bericp1 opened 6 years ago

bericp1 commented 6 years ago

This is a Question

Description

We have an interesting use case I'm having a hard time reasoning about even though it doesn't seem to complex or out there.

We're using a relational database via RDS that our serverless functions interact with along with knex to manage that interaction. We have migrations bundled into all of that of course and my aim is to be able to run those in our cloud environment(s) via remotely invoking a function instead of having to SSH into a leader server of some sort running the codebase.

The crux here is multi-fold:

So basically my question is, how do we handle dynamic requires with serverless webpack where the files being dynamically required at runtime also have to be transpiled first and packaged with the function? Or maybe recommendations on an atlernative approach?

Right now we're using babel-node to run migrations via package.json scripts and that works fine but doesn't address the use case of having a migrator serverless function that invokes the migrations.

Similar or dependent issue(s):

Additional Data

bericp1 commented 6 years ago

Options we're considering:

geovanisouza92 commented 6 years ago

@bericp1 This is a webpack concern, not serverless-webpack. Basically you need to include a require context inside your ~webpack configuration~ code.

bericp1 commented 6 years ago

@geovanisouza92 Interesting I'll investigate that.

I had posted the issue here primarily due to the final bullet:

  • we're using individually: true in our ~package.json~ serverless.yml so we're required to use serverless-webpack's automatic entry resolution in our webpack config

I suppose I thought that since serverless-webpack took control of entry in this secnario we were out of luck including other files in the webpack build.

Looks promising, thanks!

HyperBrain commented 6 years ago

Hi @bericp1

I had posted the issue here primarily due to the final bullet:

Thanks for the issue 👍 . It is good to post issues here, even if they might turn out to be solved outside of the plugin. This will help others that run into them and just search for "sls-webpack + issue description" so that they can find a proper solution immediately.

@geovanisouza92 💯 for the help

MikeRippon commented 3 years ago

Sorry to dig up an old issue, but for others that get here via google, the knex docs have an example of loading scripts inside webpack bundles here: https://knexjs.org/#custom-migration-sources