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

Add serverless-webpack support #135

Open
vincentsolutions opened this issue Oct 29, 2017 · 0 comments
Open

Add serverless-webpack support #135

vincentsolutions opened this issue Oct 29, 2017 · 0 comments

Comments

@vincentsolutions
Copy link

vincentsolutions commented Oct 29, 2017

Currently, the emulator doesn't seem to be able to work with the serverless-webpack plugin when using sls run.
Even though everything is setup in my serverless.yml file, it doesn't seem to compile it with webpack before loading the functions.

For the time being, I found the following workaround:

  1. Have 2 versions of your yml files (i.e. serverless.yml & serverless-webpack.yml)
  2. Update the serverless-webpack.yml handlers to load the functions from dist/{functionName}/{functionName}.{handlerName}
  3. Run serverless webpack --out dist from the service.
  4. Swap the yml files name (so that the serverless.yml is now the one loading from the dist directory)
  5. Run sls run as usual, but this time it will load the functions from the precompiled webpack dist directory.

I created some helper scripts in my package.json to make this process a little easier:

"scripts": {
    "change-config": "mv serverless.yml serverless-temp.yml && mv serverless-webpack.yml serverless.yml && mv serverless-temp.yml serverless-webpack.yml",
    "sls-webpack-run": "npm run-script change-config && serverless webpack --out dist && npm run-script change-config && sls run"
  }

Please note that if you want to use those scripts, the serverless.yml file must be the one loading the handlers from the dist directory prior to running npm run-script sls-webpack-run, since it will switch back the files before compiling with webpack and it switches them back when it's done. This is to ensure that every time we run sls-run, we load the functions from the dist directory, even if we didn't re-compile it with webpack beforehand.

But it'd be great if there was a way to use the serverless-webpack plugin with sls-run out-of-the-box!

@vincentsolutions vincentsolutions changed the title Add webpack support for emulator and event-gateway Add serverless-webpack support Oct 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant