const Webpack = require('webpack')
const package = require('./package.json')
const { join } = require('path')

const externals = () => {
  const dependencies = package.dependencies

  return Object
    .keys(dependencies)
    .reduce((modules, module) =>
      Object.assign({}, modules, { [module]: `commonjs ${module}` }),
      {}
    )
}

module.exports = {
  context: join(__dirname, './build'),
  entry: {
    boleto: './resources/boleto/index.ts',
    database: './functions/database/index.ts'
  },
  output: {
    path: join(__dirname, './dist'),
    libraryTarget: 'commonjs2',
    filename: '[name].js'
  },
  devtool: 'inline-source-map',
  target: 'node',
  externals: externals(),
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['source-map-loader'],
        enforce: 'pre'
      }
    ]
  },
  plugins: [
    new Webpack.DefinePlugin({
      'process.env':  {
        'ENV': JSON.stringify('production'),
        'NODE_ENV': JSON.stringify('production'),
      }
    }),
    new Webpack.BannerPlugin({
      banner: `
        require("source-map-support").install();
        require("core-js");
      `,
      raw: true,
      entryOnly: false
    }),
    new Webpack.CopyWebpackPlugin({
      from: './build/database/migrations',
      to: './dist/migrations'
    })
  ]
}

@@ -28,16 +28,73 @@
 bpack')%0A
+const CopyWebpackPlugin = require('copy-webpack-plugin')%0A
 const pa
@@ -500,17 +500,17 @@
 o/index.
-t
+j
 s',%0A    
@@ -547,17 +547,17 @@
 e/index.
-t
+j
 s'%0A  %7D,%0A
@@ -1279,24 +1279,16 @@
     new 
-Webpack.
 CopyWebp
@@ -1293,24 +1293,25 @@
 bpackPlugin(
+%5B
 %7B%0A      from
@@ -1319,14 +1319,8 @@
  './
-build/
 data
@@ -1354,13 +1354,8 @@
  './
-dist/
 migr
@@ -1361,22 +1361,66 @@
 rations'
+,%0A      context: join(__dirname, './build')
 %0A    %7D
+%5D
 )%0A  %5D%0A%7D%0A

fix copy-webpack-plugin usage