How can the test directory be excluded from webpack packaging?

Right now, my test directory code is getting included in the webpack package built and uploaded to AWS Lambda. How can I exclude this directory? I tried different things from but none have helped so far.

By default webpack should have tree shaking enabled which would exclude the test files unless you’re including them some how. Are you able to share your webpack config and the location of your test folder?


const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: './handler.js',
  target: 'node',
  externals: [nodeExternals()],
  plugins: [
    new webpack.IgnorePlugin(/\.(md|yml.encrypted|sh|vm)$/)
  module: {
    loaders: [
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: "babel-loader"
        test: /\.json$/,
        loader: "json-loader"
        test: /\.yml$/,
        loader: "yml"

I’d like to exclude node_modules, test, scripts, bin directories.