【问题标题】:Babel CLI is extremely slowBabel CLI 非常慢
【发布时间】:2016-05-16 15:48:34
【问题描述】:

所以我跟着安装here,但是babel编译需要很长时间,即使是小文件:

app.js

let app = 1;

.babelrc

{ "presets": ["es2015"] }

package.json

"scripts": {
    "build": "babel app.js -o dist/app.js"
},
"devDependencies": {
    "babel-cli": "^6.4.5",
    "babel-preset-es2015": "^6.3.13"
}

然后npm run build 将需要大约 30 秒来编译。

我正在使用npm@3.3.12

【问题讨论】:

  • 无法复制。不使用 NPM 直接运行命令会发生什么? node_modules/.bin/babel app.js -o dist/app.js
  • 如果你在 npm 3 上你应该很好。也许清除你的 node_modules 并重新安装以确保?或者查看 node_modules 并确保您的依赖项都正确展平。
  • 是的,来自我的安装,rm -rf node_modulesnpm cache cleannpm install成功了。

标签: npm ecmascript-6 babeljs


【解决方案1】:

您可能也在编译node_modulesbower_components

您可以尝试在您的项目.babelrc 中添加ignore 属性,如下所示:

{
  ...
  "ignore": /(node_modules|bower_components)/
  ...
}

希望这能解决您的问题

【讨论】:

    【解决方案2】:

    2019 年 9 月更新

    发现升级到 Babel 7 解决了这个问题。也许试试:

    $ npm install --save-dev @babel/core @babel/node @babel/preset-env
    

    您的 package.json 应包含以下内容:

     "devDependencies": {
        "@babel/core": "^7.6.0",
        "@babel/node": "^7.6.1",
        "@babel/preset-env": "^7.6.0"
      }
    

    我的.babelrc文件如下:

    {
      "presets": ["@babel/preset-env"]
    }
    

    现在,当我跑步时:

    npx babel-node src/index.js
    

    性能几乎是瞬间完成的(使用 babel 6 需要 20 多秒)。

    请参阅babel 7.5 docs 了解更多详情。

    另外,有关升级的参考,请参阅this stackoverflow question & answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      • 2015-06-14
      相关资源
      最近更新 更多