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:
import/export module syntax in our migrations as well since it's used everywhere else in our codebase and it would feel a little awkward to have a directory where import/export isn't allowed.knex works.individually: true in our ~package.json~ serverless.yml so we're required to use serverless-webpack's automatic entry resolution in our webpack configSo 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):
"serverless-webpack": "^5.1.5""webpack": "^4.2.0""serverless": "^1.28.0"Options we're considering:
serverless-webpack's scripts to run babel on the migrations files after the webpack build (we're currently using webpack-copy-plugin to copy them in)import/export and just use commonjs module.exports :(@bericp1 This is a webpack concern, not serverless-webpack. Basically you need to include a require context inside your ~webpack configuration~ code.
@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!
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
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
Most helpful comment
Hi @bericp1
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