javascript - Babili 缩小但不转译

标签 javascript node.js ecmascript-6 babeljs

我被 babili 困住了.

我需要转译,然后缩小用ES6编写的javascript。所以我使用以下方法安装了该软件包:

npm install babili --save-dev

并制作了包含预设的.babelrc文件:

{"presets": ["es2015"]}

现在我尝试了以下命令

./node_modules/.bin/babili public/js/rt.socket.js --out-file public/test.min.js

它确实给出了缩小但不转译。这可能是什么原因? `

最佳答案

Babili 不使用.babelrc 。根据 README :

Note that, because the babili command uses the default preset with no-babelrc, you cannot set any non-default options in the preset's plugins with this command. To do this, you can use the babel command with the options set in a .babelrc. See the preset docs for more information on how to do this.

解决方案是使用 Babel 和 babel-preset-babili预设,如 Babel preset 中所述自述文件部分(假设您已经安装了 Babel):

Install

npm install babel-preset-babili --save-dev

Usage

You'll most likely want to use it only in the production environment. Check out the env docs for more help.

Options specific to a certain environment are merged into and overwrite non-env specific options.

.babelrc:

{
  "presets": ["es2015"],
  "env": {
    "production": {
      "presets": ["babili"]
    }
  }
}

然后你需要设置环境变量,它可能类似于 BABEL_ENV=production npm run build

关于javascript - Babili 缩小但不转译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44142480/

相关文章:

javascript - 单击以显示更多 - 也许是 JS?

javascript - 客户端找不到 socket.io.js

node.js - 如何启动 node.js 应用程序然后返回命令行并导航

javascript - 使用箭头函数设置变量

javascript - 如何对不同坐标下的ImageData进行模糊处理

javascript - 如何在选择标签上打开新选项卡

node.js - 从 firebase 返回响应的正确方法是 Google Cloud Pub/Sub 触发器

javascript - es6从文件中获取json数据

javascript - 使用 lodash 展平嵌套对象

javascript - 如何使用浅层渲染测试装饰后的 React 组件