Marko: Why do you overload node.js require() to load templates?

Created on 8 Mar 2017  路  4Comments  路  Source: marko-js/marko

Don't understand. Why not just use a function?

Most helpful comment

That's a good question. We're actually going to make some related changes that we have been meaning to make that I suspect you will like. We'll get back to you soon.

All 4 comments

Convenience. I don't believe it's required

That's a good question. We're actually going to make some related changes that we have been meaning to make that I suspect you will like. We'll get back to you soon.

@andersea It actually hooks into a built-in extension system that's been part of require() since almost the beginning, but it has also been deprecated for nearly as long (require.extensions).

It was originally decided that the added convenience outweighed the risk (#78). However, with the related changes Patrick mentioned, this may be the perfect time to rethink that.

Also, it's not necessary to use the extension, the old way still works without it:

var template = require('marko').load(require.resolve('./path/to/template.marko'));

Thanks for that answers. Closing.

Was this page helpful?
0 / 5 - 0 ratings