const path = require('path')
// eslint-disable-next-line import/no-unresolved
const slsw = require('serverless-webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')

const addBabelPolyfill = (slsEntries) => {
  return Object.keys(slsEntries)
    .reduce((acc, key) => Object.assign(acc, {
      [key]: ['babel-polyfill', slsEntries[key]]
    }), {})
}

module.exports = {
  entry: addBabelPolyfill(slsw.lib.entries),
  target: 'node',
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      exclude: /node_modules/
    }]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  externals: [
    'aws-sdk'
  ],
  plugins: [
    new CopyWebpackPlugin([
          { from: '.serverless-secret.json' }
    ])
  ]
}

@@ -326,16 +326,47 @@
 lyfill',
+ 'source-map-support/register',
  slsEntr
@@ -472,16 +472,41 @@
 'node',%0A
+  devtool: 'source-map',%0A
   module

Add source map to get prettier stacktrace.