webpack代码没有转换为ES5

时间:2018-02-19 21:00:14

标签: javascript internet-explorer webpack babel transpiler

所以我现在已经经历了一些变种的配置,并且出于某种原因,某些webpack代码没有被生成|| babel-loader生成到es5开发(指定,因为我知道webpack-dev-server已移除support for it

我的.babelrc看起来像这样:

{
  "plugins": ["transform-object-assign", "transform-async-to-generator", "transform-object-rest-spread", "transform-class-properties"],
  "presets": [
    ["env", {
      "targets": { "browsers": ["chrome >= 49", "firefox >= 54", "ie >= 9"] }
    }],
    "react"
  ]
}

我已按照文档的建议删除es2015并切换到presets -> env,但它也不适用于那里。

我的webpack配置如下所示:

  module: {
    rules: [{
      enforce: 'pre',
      test:    /\.(js|less|css)$/,
      exclude: [/node_modules/, /bower_components/],
      loader:  StringReplacePlugin.replace({ replacements })
    }, {
      test: /\.(html|svg)$/,
      use:  'raw-loader'
    }, {
      test:    /\.js$/,
      exclude: [/node_modules/, /bower_components/],
      use:     {
        loader: 'babel-loader'
      }
    },

对于一个有效的破解示例,您可以加载https://www.useloom.com/share/7d602553ce22425c882e96eb58ff7417

在任何互联网资源管理器浏览器中,您会看到来自此代码的Const must be initializedfor (const key of Object.keys(ansiStyles)) {位于此模块中:

"use strict";
/* WEBPACK VAR INJECTION */(function(process) {
const escapeStringRegexp = __webpack_require__(1618);
const ansiStyles = __webpack_require__(1619);
const supportsColor = __webpack_require__(1193);

有没有人遇到过这个? babel配置有问题,还是与webpack有关?

这是相关的package.json(那里有一些额外的模块,因为我搞乱了事情)

"babel-cli": "^6.18.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-loader": "^7.1.2",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-watch": "^2.0.7",
"babelify": "^7.3.0",
"webpack": "^3.9.1",
"webpack-dev-server": "2.7.1"

0 个答案:

没有答案