ejs
ejs copied to clipboard
Missing dependencies from included files (include with parenthesis)
Following PR https://github.com/mde/ejs/pull/71/files, i would expect to have all dependencies defined and part of fn.dependencies or returnedFn.dependencies. I'm using EJS (version 2.6.1) within webpack through this loader : https://github.com/rorkflash/ejs-webpack-loader
If I have this template :
<%- include('../ejs/footer.ejs') %>
The dependencies are `[].
If I change template to
<%- include ../ejs/footer.ejs %>
The dependencies are `['/absolute/path/to/src/folder/ejs/footer.ejs'].
With the parenthesis approach (which seems to be the official way to go with EJS), the dependency is missing and compile cannot be relaunch when the dependency changes (it works when the root template is updated, but it is not handy =/).
As I need to pass parameters to my template, I need the parenthesis approach and so, i can't have hot recompile ='(
It makes sense that this would happen — the includedirective is a simple JS function that grabs the template off disk, evaluates it, and inserts the result at that include call site. It does this recursively, and doesn't know anything about include calls further down the tree until it actually runs them.
The older preprocessor directive (which will go away in future versions) already relies on regex, and actually inlines the source code of the included template into the parent template, before trying to run the entire thing.
I'm taking a look at your patch right now. Just want to make sure it won't interfere with future plans to make the disk I/O for grabbing template text asynchronous.
I've added a bunch of comments to PR #428. Interested to hear your thoughts.