Webpack 不会将打字稿编译为 ES5?

时间:2020-12-26 03:59:29

标签: javascript typescript webpack

我正在尝试将我的代码编译为 ES5。我为此使用了 typescript+webpack。然而,即使遵循了所有关于此事的官方指南和各种教程,我仍然在 webpack 的最终 bundle.js 文件输出中获得箭头功能

这是我的 webpack.config.js 文件

const path = require( 'path' );

module.exports = {

    // generate source maps
    devtool: 'source-map',

    // bundling mode
    mode: 'production',

    // entry files
    entry: './src/index.ts',

    // output bundles (location)
    output: {
        path: path.resolve( __dirname, 'dist' ),
        filename: 'bundle.js',
    },

    // file resolutions
    resolve: {
        extensions: [ '.ts', '.js' ],
    },

    // loaders
    module: {
        rules: [
            {
                test: /\.tsx?/,
                use: {
                    loader: 'ts-loader',
                    options: {
                        transpileOnly: true,
                    }
                },
                exclude: /node_modules/,
            }
        ]
    },

    // set watch mode to `true`
    watch: true
};

这是我的 tsconfig.json 文件

{
  "compilerOptions": {
      "noImplicitAny": true,
      "target": "ES5",
      "module": "ES2015",
      "sourceMap": true,
      "importsNotUsedAsValues": "preserve"
  }
}

这是我的 package.json 文件摘录:

  "devDependencies": {
    "ts-loader": "^8.0.12",
    "typescript": "^4.1.3",
    "webpack": "^5.11.0",
    "webpack-cli": "^4.3.0"
  },

输出 bundle.js 文件总是包含箭头函数,我想去掉: enter image description here

0 个答案:

没有答案