title: Webpack bundles tests (enzyme / jest) in the production env
body: <p>I have issue with Webpack building production bundle with test files + test libs included.</p>
  
  <p>In this case it is Enzyme and Jest which we use.</p>
  
  <p>Webpack version 3.10.0</p>
  
  <p>Webpack.build.js</p>
  
  <pre><code>const path = require('path');
  const webpack = require('webpack');
  const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  
  module.exports = function() {
    return {
      entry: './src/index.js',
      output: {
        path: path.resolve(__dirname, '../build'),
        filename: 'bundle.js',
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: [
              /node_modules/,
              /__snapshots__/,
              /test-util/,
            ],
            loader: 'babel-loader'
          },
          {
            test: /\.scss$/,
            use: [
              {
                loader: 'isomorphic-style-loader'
              },
              {
                loader: 'css-loader'
              },
              {
                loader: 'sass-loader'
              }
            ]
          },
        ]
      },
      plugins: [
        new UglifyJsPlugin(),
        new webpack.DefinePlugin({
          'process.env': {
            'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
          }
        }),
      ]
    }
  };
  </code></pre>
  
  <p>Here is the file structure
  <a href="https://i.stack.imgur.com/C03At.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C03At.png" alt="enter image description here"></a></p>
  
  <p>I have tried to workaround the issue by placing Enzyme as external resource in webpack.</p>
  
  <pre><code>externals: {
    'enzyme': 'enzyme',
    'enzyme-adapter-react-16': 'enzyme-adapter-react-16',
  }
  </code></pre>
  
  <p>That does exclude it from build but (it is workaround) it still builds the snapshot files
  <a href="https://i.stack.imgur.com/di4xa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/di4xa.png" alt="enter image description here"></a></p>
  
  <p>I have tried to make "test" regex of babel-loader more specific and exclude test files but it failed.</p>
  
  <p>This is new project and I spent whole day trying to make it bundle only what is necesary. Drained all of my know-how, my google know-how and know-how of the poeple I know or I work with. Hope that SO will be smarter :)</p>