koajs / ejs

a koa view render middleware, support all feature of ejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide own filesystem

Reeywhaar opened this issue · comments

Right now koa-ejs uses only actual node's filesystem.

This becomes trouble when using it with webpack-dev-middleware.

My case: I have server that uses dev middleware to manage compilation for client-side javascript. It keeps all generated assets in memory. I am able to access it's memory filesystem via devMiddlewareInstance.fileSystem which is memfs node's fs api compliant fs.

But koa-ejs accepts only path to root.

So, solution is either to add fs property to koa-ejs options which will accept any node's fs api compliant type. Or second way is to provide root as callback of type (templateFilename: string) => Promise<string>, like: root: (templateFilename) => myfs.readFilePromise(templateFilename).

What do you think?

@Reeywhaar, I think the best apport to keep the code cleaner is by providing an fs option as you mention. If it's okay, for your use case I will ship it in the next release (check it here)

@Reeywhaar, added I will notify you when I can publish the release!