title: How to transpile ES6 to ES5 for 3rd party libs?
body: <p>I have a webpack setup that works almost fine, but I see an error that UglifyJS emits when I import some 3rd party libs that are written in ES6. Here is an example from <code>node-postgres</code>:</p>
  <pre><code>module.exports = {
    prepareValue: function prepareValueWrapper (value) {
      // this ensures that extra arguments do not get passed into prepareValue
      // by accident, eg: from calling values.map(utils.prepareValue)
      return prepareValue(value)
    },
    normalizeQueryConfig,
    postgresMd5PasswordHash,
    md5
  }
  </code></pre>
  <p>Here is the how it should look in ES5:</p>
  <pre><code>module.exports = {
    prepareValue: function prepareValueWrapper (value) {
      // this ensures that extra arguments do not get passed into prepareValue
      // by accident, eg: from calling values.map(utils.prepareValue)
      return prepareValue(value)
    },
    normalizeQueryConfig: normalizeQueryConfig,
    postgresMd5PasswordHash: postgresMd5PasswordHash,
    md5: md5
  }
  </code></pre>
  <p>When the original code is processed by UglifyJS, I see this error:</p>
  <blockquote>
  <p>ERROR in proxy.js from UglifyJs</p>
  <p>Unexpected token: punc (,) [proxy.js:382,22]</p>
  </blockquote>
  <p>Which points to the code from above.</p>
  <p>As I am compiling a TypeScript project, I suspect I need to process 3rd party libs code through some transpiler inside Webpack flow to convert them to ES5 before bundling.</p>
  <p>Here is my <code>webpack.config.js</code>:</p>
  <pre><code>const path = require('path');
  
  const root = (dir) =&gt; {
      return path.resolve(__dirname, dir);
  };
  
  module.exports = {
      entry: './src/main.ts',
      module: {
          rules: [
              {
                  test: /\.ts$/,
                  use: 'ts-loader',
                  exclude: /node_modules/
              }
          ]
      },
      resolve: {
          extensions: [&quot;.ts&quot;, &quot;.js&quot;],
          modules: [root('node_modules'), root('src')]
      },
      output: {
          filename: 'proxy.js',
          path: path.resolve(__dirname, 'build')
      },
      target: 'node'
  };
  </code></pre>
  <p>How can I do it?</p>