【问题标题】:mustache-js views don't auto-refresh with nodemonmustache-js 视图不会使用 nodemon 自动刷新
【发布时间】:2017-05-11 06:43:00
【问题描述】:

我使用 nodemon 已经有一段时间了,这样我就不用在编辑文件时重新启动服务器了。

现在我切换到使用 mustache.js 模板,神奇地始终保持最新状态不再起作用 - 我现在需要手动重新启动服务器以使我的更改生效。

这是一个错误吗?配置错误?

澄清一下:每当我编辑 .mustache 文件时,我都需要手动重新启动服务器以查看我的更改。

【问题讨论】:

    标签: node.js mustache nodemon


    【解决方案1】:

    为了指定 Nodemon 应该在哪些文件上自动刷新,您可以设置 package.json 以使用 nodemon.json 配置文件启动 Nodemon,其中包括要观看的文件扩展名。例如:

    添加到 package.json 文件:

      "scripts": {
        "dev": "nodemon --config nodemon.json"
      },
    

    创建 nodemon.json 文件:

    {
        "verbose": true,
        "execMap": {
            "js": "node --harmony"
        },
        "script": "server.js",
        "ext": "js mustache"
    }
    

    现在运行时,您应该看到 nodemon 正在监视 .js.mustache 文件:

    > npm run dev
    
    [nodemon] 1.11.0
    [nodemon] reading config nodemon.json
    [nodemon] watching extensions: js,mustache 
    [nodemon] starting `node --harmony server.js`
    [nodemon] child pid: 7740
    [nodemon] watching 5 files
    

    【讨论】:

      【解决方案2】:

      来自this answer 我将启动脚本更改为

      "start": "nodemon -e js,mustache ./server.js",

      【讨论】:

        【解决方案3】:

        更改 html 小胡子模板不会导致服务器使用 nodemon 重新启动。

        但就我而言,我可以简单地编辑一个 html mustache 模板文件,保存它,然后刷新页面(无需重新启动服务器),我可以看到所做的更改。

        也许,请尝试检查您的路由并确保您正在呈现正确的模板文件。

        【讨论】:

        • 我正在渲染正确的文件...但是在我的设置中,我必须重新启动节点服务器才能使 mustache 文件中的更改生效。
        猜你喜欢
        • 2018-04-20
        • 2018-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-02
        • 2014-04-29
        • 2018-08-26
        • 1970-01-01
        相关资源
        最近更新 更多