https://deno.land/x/[email protected]
denon是 deno
中 nodemon 的替代品。denon会监视文件的改变,并自动重新启动程序,重新编译更改的源代码。
⚠️ Make sure you are using deno version ^1.6.0 to install this executable. You can upgrade running deno upgrade.
deno版本需要在^1.6以上
deno install -qAf --unstable https://deno.land/x/denon/denon.ts
deno install -qAf --unstable https://x.nest.land/denon/denon.ts
mac环境,在终端输入open -e ~/.bash_profile
添加如下内容
# denon
export PATH="/Users/zhouwei/.deno/bin:$PATH"
检查命令是否可用, 能打印信息即成功
$ denon --version
$ denon run app.ts
$ denon run --allow-env app.ts
- 只是简单使用可以生成json配置文件
- 如果较复杂及灵活的配置建议使用.ts配置文件,可以添加环境变量及代码块操作
// 生成json配置文件
denon --init
// 生成.ts配置文件
denon --init typescript
配置文件内容如下:
// scripts.json
{
"$schema": "https://deno.land/x/[email protected]/schema.json",
"scripts": {
"start": {
"cmd": "deno run day1/hello.ts",
"desc": "run my app.ts file"
},
"fileServer": {
"cmd": "deno run day1/fileServer.ts",
"desc": "run my fileServer.ts file"
}
}
}
// scripts.config.ts
import { DenonConfig } from "https://deno.land/x/[email protected]/mod.ts";
const config: DenonConfig = {
scripts: {
start: {
cmd: "deno run day1/hello.ts",
desc: "run my app.ts file",
},
fileServer: {
cmd: "deno run day1/fileServer.ts",
desc: "run my fileServer.ts file",
},
},
};
export default config;
$ denon start
$ denon fileServer
// scripts.json
{
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "Run the main server.",
"env": {
"PORT": 3000
}
}
}
}
// scripts.config.ts
import { DenonConfig } from "https://deno.land/x/[email protected]/mod.ts";
import { config as env } from "https://deno.land/x/dotenv/mod.ts";
const config: DenonConfig = {
scripts: {
start: {
cmd: "deno run day1/hello.ts",
desc: "run my app.ts file",
},
fileServer: {
cmd: "deno run day1/fileServer.ts",
desc: "run my fileServer.ts file",
env: env()
},
},
};
export default config;
{
"allow": {
"read": "/etc,/tmp", // --allow-read=/etc,/tmp
"env": true // --allow-env
},
"allow": [
"run", // --allow-run
"net" // --allow-net
],
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "Run the main server.",
// available options...
"allow": ["env", "write"],
"unstable": true
// running `denon start` will resolve in
// deno run --allow-env --allow-write --unstable app.ts
"watch": true
}
}
}
import { DenonConfig } from "https://deno.land/x/[email protected]/mod.ts";
import { config as env } from "https://deno.land/x/[email protected]/mod.ts";
const config: DenonConfig = {
scripts: {
start: {
cmd: "deno run day1/hello.ts",
desc: "run my app.ts file",
},
fileServer: {
cmd: "deno run day1/fileServer.ts",
desc: "run my fileServer.ts file",
env: env(),
allow: ["net", "read"],
},
},
};
export default config;