2

Im trying to compile following code:

// src/index.tsx
console.log(() => {})

When I use "target": "es6" in tsconfig I get following code (all ok):

(()=>{"use strict";console.log((()=>{}))})();

But when I use "target": "es3" in tsconfig the generated code still contains SOME arrow functions (that arent supported in ES3):

(()=>{"use strict";console.log((function(){}))})();

What's the point of transpiling just my code but not the own webpack generated one?

This is my webpack config:

module.exports = {
    mode: "development",
    devtool: "inline-source-map",
    entry: "./src/index.tsx",
    output: {
        filename: "webpackbundle.js"
    },
    resolve: {
        // Add `.ts` and `.tsx` as a resolvable extension.
        extensions: [".ts", ".tsx", ".js"]
    },
    module: {
        rules: [
            // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
            { test: /\.tsx?$/, loader: "ts-loader" }
        ]
    }
};
Rashomon
  • 5,962
  • 4
  • 29
  • 67
  • Does this answer your question? [Webpack generates arrow function in ES5](https://stackoverflow.com/questions/64620341/webpack-generates-arrow-function-in-es5) –  Mar 02 '21 at 15:03
  • The solution of that question is not supported in webpack 5 – Rashomon Mar 02 '21 at 17:00
  • this is the [answer you want I think](https://stackoverflow.com/a/64622063/542251) – Liam Mar 02 '21 at 17:06
  • You are right, I was adding the suggested configuration to tsconfig instead of webpack. The second response confused me – Rashomon Mar 02 '21 at 17:16

0 Answers0