Skip to content

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

@bericp1

Description

@bericp1

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:

  • we want to use es6 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.
  • our migration files are intended to be required dynamically via a directory listing at runtime because that's how knex works.
  • 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

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

  • Serverless-Webpack Version you're using: "serverless-webpack": "^5.1.5"
  • Webpack version you're using: "webpack": "^4.2.0"
  • Serverless Framework Version you're using: "serverless": "^1.28.0"
  • Operating System: macOS High Sierra
  • Stack Trace (if available):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions