Webpack 4 + Babel 在转译后的代码中保留 const

Webpack 4 + Babel leaving const in transpiled code

我正在尝试让我的代码在不支持 ES6 的 Android 4.1 Webview 上运行。

但是我收到这个错误:

Uncaught SyntaxError: Use of const in strict mode.

.babelrc 配置

{
  "plugins": [
    "lodash"
  ],
  "presets": [
    "@babel/preset-react",
    [
      "@babel/preset-env",
      {
        "targets": {
          "android": "4.1"
        },
        "useBuiltIns": "usage",
        "forceAllTransforms": true
      }
    ],
    "@babel/preset-stage-0"
  ]
}

webpack.config.js

rules: [
      {
        enforce: 'pre',
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: "eslint-loader"
      },
      {
        test: /\.jsx?$/,
        loaders: 'babel-loader',
        options: {
          plugins: ['lodash']
        },
        exclude: /(node_modules|bower_components)/
      },
   ]

我发现问题是由 "query-string" 模块引起的,它是另一个包的依赖项。 如 github 所述,我明确安装了版本 5。然后一切正常。

Github: query-string

This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, use version 5: npm install query-string@5.