简体   繁体   中英

Webpack + Typescript + Babel producing ES6 syntax

I'm trying to use Webpack and babel to create an ES5 compatible output of my typescript code. The resulting bundle.js file however still includes ES6 keywords such as let . How do I go about making the output truly ES5 compliant?

Below is my webpack config file:

const path = require('path');

module.exports = {
  mode: "production",
  entry: './src/intersight.ts',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                ['@babel/preset-typescript'],
                ['@babel/preset-env', {
                  targets: "defaults",
                  forceAllTransforms: true
                }]
              ],
            }
          },
        ],
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    modules: [
      path.resolve('./node_modules')
    ],
    fallback: {
      crypto: require.resolve('crypto-browserify'),
      http: require.resolve('stream-http'),
      https: require.resolve('https-browserify'),
      stream: require.resolve('stream-browserify'),
      url: require.resolve('url'),
    }
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    libraryTarget: 'umd',
    globalObject: 'this'
  },
};

Look at this doc . If you remove in presets array "targets: default" it should target the oldest browsers per doc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM