bespoken-cookbook / serverless-plugin-bespoken

:zap: Serverless plugin to use our bst proxy tool

Home Page:https://bespoken.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for serverless-webpack plugin

cosemansp opened this issue · comments

Is there support for running webpack bundeling with bespoken?

I use this plugin and just started using serverless-webpack plugin and am interested in addressing this.

Are you having an issue with the --inject-passthru option or another behavior?

I've opened a PR that addresses an issue with the --inject-passthru option when using serverless-webpack #13

I use serverless-webpack and running sls proxy works, but as soon as I send a LaunchRequest I get the error:

INFO  2018-08-07T21:06:57.698Z Forwarding localhost:10000
Error: Cannot find module '/my-dir/src/index'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Function.load (/my-dir/node_modules/bespoken-tools/lib/core/node-util.js:6:16)
    at ModuleManager.module (/my-dir/node_modules/bespoken-tools/lib/client/module-manager.js:49:43)
    at LambdaServer.invoke (/my-dir/node_modules/bespoken-tools/lib/client/lambda-server.js:84:43)
    at IncomingMessage.<anonymous> (/my-dir/node_modules/bespoken-tools/lib/client/lambda-server.js:34:22)
    at emitNone (events.js:106:13)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Running with --inject-passthru gave the same error. I should note that my skill is written in typescript and the main handler is in src/index.ts.

This is my serverles.yml

service: serverless-webpack-typescript

# Add the serverless-webpack plugin
plugins:
  - serverless-webpack
  - serverless-plugin-bespoken

provider:
  name: aws
  runtime: nodejs8.10
  stage: ${opt:stage, 'dev'} # default stage is dev, but you can override it.
  region: us-east-1
  memorySize: 256
  cfLogs: true # AWS Cloudformation logging

custom:
  webpack:
    webpackConfig: './webpack.config.js'   # Name of webpack configuration file
    includeModules: true   # Node modules configuration for packaging
    # packager: 'npm'   # Packager that will be used to package your external modules

# package:
  # individually: true # Enables individual packaging for each function. If true you must provide package for each function. Defaults to false

functions:
  skill:
    handler: src/index.handler
    events:
      - alexaSkill

And this is my webpack.config.js

const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
console.log(slsw.lib.entries);
module.exports = {
  entry: slsw.lib.entries,
  module: {
    rules: [
      {
        test: /\.ts(x?)$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      }
    ]
  },
  optimization: {
    // We no not want to minimize our code.
    minimize: false
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false
  },
  devtool: 'nosources-source-map',
  // externals: [nodeExternals()],
  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.json']
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, 'dist/'),
    filename: '[name].js',
    sourceMapFilename: '[file].map'
  },
  target: 'node',
};

How is this issue moving ? Was #13 meant to solve this ? Is it documented anywhere how to use this plugin with serverless webpack ? Would be happy to help if I got any direction to contribute and move it forward.