Skip to content

Question: hooks *after* compile – but *before* run #315

@dwelch2344

Description

@dwelch2344

This is a Question

Description

New to plugin development, so apologies if we're missing something incredibly obvious. We're attempting to write a plugin that runs after webpack but before deploy / offline / etc, but can't seem to hit the hook. We can run after validate, just fine (with after:webpack:validate:validate)

Plugin thus far is dead simple. Uncomment the validate hook to see it in action. So far the plugin is just running in .serverless_plugins – and is imported after serverless-webpack (though we've tried before as well)

Are we missing something obvious? Or is there not a hook for the compilation?

Thanks

'use strict';

class ServerlessPlugin {
  constructor(serverless, options) {    
    this.serverless = serverless;
    this.options = options;

    this.commands = {
      welcome: {
        usage: 'Helps you start your first Serverless plugin',
        lifecycleEvents: [
          'hello',
        ],  
        commands: {
          compile: {
            type: 'entrypoint',
            lifecycleEvents: [
              'compile',
            ],
          },
        }
      },      
    };

    this.hooks = {
      // 'after:webpack:validate:validate': this.validate.bind(this),
      'webpack:compile:compile': this.debug.bind(this),
      // 'before:offline:start': this.debug.bind(this),
      // 'offline:start': this.debug.bind(this),
      'before:offline:start': this.debug.bind(this),
      // 'before:offline:start:init': this.debug.bind(this),      
    };
  }

  validate(){
    for(let i = 0; i < 15; i++){
      console.log('validate')
    }
  }

  debug(){
    throw new Error('i should blow up here debug')
  }


  compile(){
    throw new Error('i should blow up here compile')
  }
}

module.exports = ServerlessPlugin;

Additional Data

  • Serverless-Webpack Version you're using:
    ^4.2.0
  • Webpack version you're using:
    ^3.10.0
  • Serverless Framework Version you're using:
    ^1.25.0
  • Operating System:
    Mac OS X - Sierra (scared to upgrade to High Sierra)

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