【Deno】denon deno热重载框架

官网

https://deno.land/x/denon@2.5.0

简介

denon是 denonodemon 的替代品。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.land源

deno install -qAf --unstable https://deno.land/x/denon/denon.ts

nest.land源

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

配置文件

  1. 只是简单使用可以生成json配置文件
  2. 如果较复杂及灵活的配置建议使用.ts配置文件,可以添加环境变量及代码块操作
生成配置文件
// 生成json配置文件
denon --init

// 生成.ts配置文件
denon --init typescript

配置文件内容如下:

 // scripts.json
{
  "$schema": "https://deno.land/x/denon@2.5.0/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/denon@2.5.0/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/denon@2.5.0/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/denon@2.5.0/mod.ts";
import { config as env } from "https://deno.land/x/dotenv@v3.2.2/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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值