我被 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 withno-babelrc
, you cannot set any non-default options in the preset's plugins with this command. To do this, you can use thebabel
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"] } } }
然后你需要设置环境变量,它可能类似于
block 引用>BABEL_ENV=production npm run build
关于javascript - Babili 缩小但不转译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44142480/