如何在命令行中直接运行node/babel脚本? [英] how to run node / babel script directly in command line?
本文介绍了如何在命令行中直接运行node/babel脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的package.json看起来像:
My package.json looks like:
{
"name": "99-nodetest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "babel-node --presets env app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "latest"
}
}
我要运行的js脚本是app.js.我无法使用 node app.js 直接运行它,因为app.js包含新的语言语法.
The js script i want to run is app.js. I cannot run it directly using node app.js because app.js contains new language syntax.
因此,我必须按照上面定义的启动脚本,使用 npm start 通过babel运行它.这里没有问题.
Thus i have to run it through babel, using npm start, as per the start script defined above. No issues here.
我的问题是如何直接在命令行中运行cmd,可以做到吗? 类似于:
My question is how to run the cmd directly in the command line, can it be done? something similar to:
npm运行babel-node --presets env app.js
npm run babel-node --presets env app.js
推荐答案
node ./node_modules/babel-cli/bin/babel-node.js --presets env app.js
这篇关于如何在命令行中直接运行node/babel脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文