如何在npm脚本中使用nodemon来构建和启动脚本? [英] How to use nodemon in npm scripts to build and start scripts?

查看:56
本文介绍了如何在npm脚本中使用nodemon来构建和启动脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"scripts": {
  "build": "babel src -d lib",
  "start": "node --use_strict ./lib/index.js",
  "watch": "nodemon lib/index.js --exec npm run build"
}

使用命令 npm run watch 导致运行以下错误命令: [nodemon]启动"npm lib/index.js运行构建"

Using the command npm run watch results in the following wrong command being run: [nodemon] starting "npm lib/index.js run build"

我该如何编写一个nodemon命令,以便在重新加载时使用babel编译代码并重新加载代码?

How would I write a nodemon command that, on reload, transpiles the code using babel and reloads the code?

推荐答案

您可以简单地使用 babel-node 运行代码,以避免显式编译.

You could simply run your code with babel-node to avoid explicit transpiling.

$ nodemon lib/index.js --exec babel-node --presets=es2015,stage-2

似乎这是推荐的使用 nodemon 的方式.code>和 babel .

It seems like this is the recommended way to use nodemon with babel.

请注意,在您的 localhost远程运行 development 环境时,运行-exec 可能有意外的副作用

Please note, running --exec could have unintended side effects when running your development environment remotely of your localhost

这篇关于如何在npm脚本中使用nodemon来构建和启动脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆