title: Tree shaking not working with webpack if class contains more than one function
body: <p>I'm using Webpack for a project (and I'm starting to regret that) and tree shaking is not working.</p>
  <p>I created a simple test library which I bundle using Rollup since Webpack cannot generate esm libraries (see here for more info about that: <a href="https://github.com/webpack/webpack/issues/2933" rel="nofollow noreferrer">https://github.com/webpack/webpack/issues/2933</a>).</p>
  <p>Here is the content of my library (which uses Typescript):</p>
  <pre><code>export class Test1 {
      addOne(x: number) {
          console.log('addOne');
          return x + 1;
      }
  }
  
  export class Test2 {
      addTwo(x: number) {
          console.log('addTwo');
          return x + 2;
      }
  }
  </code></pre>
  <p>Once I bundle it with Rollup, I get this:</p>
  <pre><code>var n = function () {
          function n() {}
          return n.prototype.addOne = function (n) {
              return console.log(&quot;addOne&quot;), n + 1
          }, n
      }(),
      o = function () {
          function n() {}
          return n.prototype.addTwo = function (n) {
              return console.log(&quot;addTwo&quot;), n + 2
          }, n
      }();
  export {
      n as Test1, o as Test2
  };
  </code></pre>
  <p>Then, I use webpack to bundle my test app that is using this library. Here is the code of the app:</p>
  <pre><code>'use strict';
  
  import { Test1 } from './test.esm';
  
  const f = new Test1();
  console.log(f.addOne(1));
  </code></pre>
  <p>Once I look at the generated bundle, the Test2 code is tree shaken and does not appear in the bundle.</p>
  <p>So far, so good.</p>
  <p>If then I add a new function to my Test2 class, like this:</p>
  <pre><code>export class Test1 {
      addOne(x: number) {
          console.log('addOne');
          return x + 1;
      }
  }
  
  export class Test2 {
      addTwo(x: number) {
          console.log('addTwo');
          return x + 2;
      }
  
      addThree(x: number) {
          console.log('addThree');
          return x + 3;
      }
  }
  </code></pre>
  <p>I get the following output from Rollup:</p>
  <pre><code>var o = function () {
          function o() {}
          return o.prototype.addOne = function (o) {
              return console.log(&quot;addOne&quot;), o + 1
          }, o
      }(),
      n = function () {
          function o() {}
          return o.prototype.addTwo = function (o) {
              return console.log(&quot;addTwo&quot;), o + 2
          }, o.prototype.addThree = function (o) {
              return console.log(&quot;addThree&quot;), o + 3
          }, o
      }();
  export {
      o as Test1, n as Test2
  };
  </code></pre>
  <p>If then I generate my app bundle with webpack and this new library, without changing anything to the code of the app using the lib, the content of Test2 is added to the output.
  What am I doing wrong here?</p>
  <p>I'm using webpack 5.12.3.</p>
  <p>My webpack config is:</p>
  <pre><code>const { merge } = require('webpack-merge');
  const common = require('./webpack.common.js');
  
  
  
  module.exports = merge(common, {
      mode: 'production',
  });
  </code></pre>
  <pre><code>const path = require('path');
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  const CopyPlugin = require('copy-webpack-plugin');
  
  module.exports = {
      resolve: {
          fallback: {
              'fs': false,
          }
      },
      entry: {
          'sample-face': './src/sample-face.js',
      },
      output: {
          filename: '[name].js',
          path: path.resolve(__dirname, 'dist'),
      },
      plugins: [
          new CleanWebpackPlugin(),
          new CopyPlugin({
              patterns: [
                  { from: 'src/index.html', to: path.resolve(__dirname, 'dist') },
                  { from: 'src/sample-face.html', to: path.resolve(__dirname, 'dist') },
                  { from: 'src/assets', to: path.resolve(__dirname, 'dist/assets') },
              ]
          })
      ]
  };
  </code></pre>