raptorjs / view-engine-dust

Dust templates view engine
Apache License 2.0
1 stars 3 forks source link

Dust templates can be updated without restart. #3

Closed deanchen closed 4 years ago

deanchen commented 9 years ago

Updates to dust templates with dust caching turned off does not reflect without server restart since require() caches the compiled module even when the compiled source changes.

patrick-steele-idem commented 9 years ago

I can merge this Pull Request, but I think this is only a partial solve since most templates should be loaded statically during initialization using code similar to the following:

// Load the template once when the module is required
var template = require('view-engine').load(require.resolve('./template.dust'));

module.exports = function render(input, out) {
    // Render the template that was loaded once
    template.render({}, out);
};

The loaded template instance will continue to hold a reference to the old compiled template even if the module is modified on disk. To solve the problem for Marko I monkey-patched the Template class in development to automatically reload the compiled template if any template is modified on disk. Please see the following code:

https://github.com/raptorjs/marko/blob/master/hot-reload/index.js

If we want to support hot reloading for templates I think we need to offer a complete solution.