Serverless offline, disable when deploying

Hello for local development, i use the serverless-offline plugin - and have this in my serverless.yaml

service: my-service

 - serverless-offline

  name: aws
  runtime: nodejs6.10

and in my package,json i am including "serverless-offline": "^3.13.5" in my devDependencies, the issue is that before I am deploying I have to comment out the plugins entry in the serverless.yaml or include the serverless-offline in thedependencies` - what is the correct way to include / exclude plugins based on deployment stage?

I expect the answer is very similar to per stage environment variables in which case it will be something like:

  stage: "${opt:stage, self:provider.stage}"
      - serverless-offline

plugins: ${self.custom.${self.custom.stage}.plugins}

Note: This hasn’t been tested so it may require a little debugging

I tried this but it doesn’t work. When running sls offline start --stage dev the console outputs: Serverless command "offline" not found.

I tested it with a really simple config:

    - serverless-offline

plugins: ${self:custom.plugins}

@stgogm Have you checked the serverless-offline plugin is installed correctly?

  - serverless-offline

Yes! of course. I’m sorry, I forgot to mention that.

If I declare the plugins like that it works as expected, but not if I reference it.

I have the same problem, and it has nothing to do with plugins… really strange!

I really need a solution for this… Any insights @buggy ?


Well, I haven’t been able to solve this, so I figured out a (terrible) workaround for this particular problem:

I created a config for each stage inside a stages folder in my project (local.yml, development.yml, staging.yml and production.yml). Each with the plugins required (serverless-offline and/or serverless-domain-manager or none).

And in my package.json I added the following (example):

  "scripts": {
    "prestart": "cp stages/local.yml serverless.yml",
    "start": "sls offline start --stage local",
    "poststart": "rm serverless.yml"

You can add something like that to each stage or deploy task as needed.

That way, each time a script is executed, the appropriate serverless.yml is assigned.