我们正在更新我们的API,Babel的Henry Zhu提醒我注意此预设,babel-preset-env以替换babel-preset- es2015and的需要babel-preset-es2018。
babel-preset-env
babel-preset- es2015
babel-preset-es2018
现在,我在理解最简单的方式来处理所有事情时遇到了困难。
如果我仅向您显示配置的当前位置,这将更加容易:
.babelrc
{ "presets": [ "env", { "targets": { "node": "current" } }, "jest" ] }
package.json
{ "scripts": { "test": "node --harmony-async-await node_modules/jest/bin/jest.js", "start:local": "NODE_ENV=localhost npm run babel-node -- warpcore/server.js", "start": "npm run babel-node -- warpcore/server.js", "babel-node": "babel-node --presets=es2015,stage-2" }, "dependencies": { "babel-polyfill": "^6.23.0" }, "devDependencies": { "babel-cli": "^6.24.1", "babel-core": "^6.25.0", "babel-eslint": "^7.2.3", "babel-jest": "^20.0.3", "babel-preset-env": "^1.6.0", "babel-preset-es2015": "^6.24.1", "babel-preset-es2018": "^1.0.0", "babel-preset-stage-2": "^6.24.1", "jest": "^20.0.4" }, "jest": { "testURL": "http://localhost:8080", "testEnvironment": "node" } }
我不确定如何组织这些事情才能最好地实现我在上面的项目符号列表。
我应该做些什么改变?
我想我可以使用了。解决方法如下:
问题中张贴的一个语法有错误,因为环境预设需要用括号括起来[](来自:http : //babeljs.io/docs/plugins/preset- env/)
正确:
{ "presets": [ ["env", { "targets": { "node": "current" } }], "jest" ] }
问题中张贴的内容可以删除以下几项:
{ "scripts": { "test": "jest --verbose", "start:local": "cross-env NODE_ENV=localhost babel-node -- app.js", "babel-node": "babel-node --presets=env" }, "dependencies": { "babel-cli": "^6.24.1", "babel-preset-env": "^1.6.0" }, "devDependencies": { "babel-eslint": "^7.2.3", "babel-jest": "^20.0.3", "jest": "^20.0.4" }, "jest": { "testURL": "http://localhost:8080", "testEnvironment": "node" } }
我认为干净得多。.babelrc如果要显式包含或排除任何预设,或指定要支持的浏览器,则可以从文件中调制预设。