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

Custom options can't be set with Serverless variables #103

Open
sammort opened this issue Oct 15, 2020 · 0 comments
Open

Custom options can't be set with Serverless variables #103

sammort opened this issue Oct 15, 2020 · 0 comments

Comments

@sammort
Copy link

sammort commented Oct 15, 2020

It's not possible to set custom option values for the plugin with Serverless Variables. For example, we are trying to disable minification of code at local stage deployment.

The reason seems to be because the /** Set custom options */ logic is run before any Serverless hooks. This means that the variables have not been interpolated.

this.custom.optimize.minify literally has the value specified in serverless.yml, for example

custom:
  optimize:
    minify: ${self:custom.enable_minify.${self:provider.stage}, 'true'}

this.custom.optimize.minify value is ${self:custom.enable_minify.${self:provider.stage}, 'true'}

I've fixed this by moving the custom options code in to the beforeCreateDeploymentArtifacts method, so that the options are set following the before:package:createDeploymentArtifacts hook. I'm not 100% confident that is a totally safe solution but it does the job.

Steps to reproduce

  1. In a serverless project, set serverless.yml
plugins:
  - serverless-plugin-optimize

custom:
  enable_minify:
    local: false
    production: true
  optimize:
    minify: ${self:custom.enable_minify.${self:provider.stage}, 'true'}
  1. Deploy with sls deploy -s local

Results You Received:

Code will be minified as part of optimized packaging steps.

Results You Expected:

Code is not minified as part of optimized packaging steps.

Environment Details:

Serverless: 2.1.1
serverless-plugin-optimize: 4.1.4-rc.1

sammort pushed a commit to sammort/serverless-plugin-optimize that referenced this issue Oct 16, 2020
sammort pushed a commit to sammort/serverless-plugin-optimize that referenced this issue Nov 5, 2020
fix: Evaluate custom options after hook fix Enigmatic-Smile#103
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