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

Notify serverless-offline when watched files trigger rebuild #488

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

aldenquimby
Copy link
Contributor

@aldenquimby aldenquimby commented Sep 15, 2023

This is my first time contributing. Please let me know what you'd like to see in terms of tests, documentation, etc - thanks!

Background

Problem

  • The --reloadHandler solution proposed in the above issue drastically hurts local dev performance on a large project

Proposal

Alternatives

class OfflineInvalidate {
  constructor(serverless) {
    this.hooks = {
      'after:webpack:compile:watch:compile': () =>
        serverless.pluginManager.spawn('offline:functionsUpdated'),
    };
  }
}
module.exports = OfflineInvalidate;
  • I'd still prefer this proposed PR, so that watching "just works" with a default setup

Copy link
Owner

@floydspace floydspace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your statement, currently, we don't have lifecycle events, so this workaround would be fair to have till the time we implement hooks, (if we ever do that)

@floydspace floydspace merged commit 20bd3fd into floydspace:master Sep 15, 2023
3 checks passed
@github-actions
Copy link

🎉 This PR is included in version 1.47.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@pslm93
Copy link

pslm93 commented Sep 19, 2023

Hi could you please provide a simple example for making hot reload work when utilizing serverless-offline + serverless-build? I am unable to get this to work. What should the watch pattern be? I see in examples that the pattern is an array but my IDE complains that the pattern must be a string. What should be done for serverless offline?
I have the following in my serverless.yml file:

plugins:
  - serverless-domain-manager
  - serverless-esbuild
  - serverless-newrelic-lambda-layers
  - serverless-prune-plugin
  - serverless-offline
  
  custom:
     esbuild:
       external:
         - deasync
         - newrelic
       watch:
         pattern: "src/**/*.(js|ts)"
       bundle: true
       minify: true
       sourcemap: true

But when I have my application running by sls offline, when I update anything in my code, the changes don't trigger a rebuild. Thank you so much for your help.

@aldenquimby
Copy link
Contributor Author

@pslm93 any chance you can link to an example repo? I have a similar configuration, and it's working for me after this PR.

To debug, I think the first step is to determine if the problem is with esbuild, or with serverless-offline. Add keepOutputDirectory: true under esbuild in your serverless.yml so you can see the .esbuild directory. Change a source file, and you should see the JS output update accordingly automatically. If it doesn't update, the problem is with esbuild and your watch config. If it does update, the problem is with serverless-offline.

@aldenquimby aldenquimby deleted the alden-offline branch October 11, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants