Closed basickarl closed 5 years ago
@basickarl please use require('marko/node-require').install();
This will enable the repo to see *.marko files.
This can just go in your root index.js and don't need to change it anymore once you set that line.
It should be noted that this page: https://markojs.com/docs/installing/
Has this code:
On the server
Require Marko views
Marko provides a custom Node.js require extension that allows you to require Marko views exactly like a standard JavaScript module. Take the following example server.js:
hello.marko
switch syntax
div -- Hello ${input.name}!
server.js
// The following line installs the Node.js require extension
// for `.marko` files. This should be called once near the start
// of your application before requiring any `*.marko` files.
require('marko/node-require');
In fact, the syntax that is not recommended is widespread throughout the docs.
@basickarl both are fine and here is when to use either:
require('marko/node-require')
Is used when you just want to allow requiring Marko files in your node server with the default config.
require('marko/node-require').install(options)
Allows you to provide additional options for the Marko files that are compiled.
The option defaults look like:
{
extensions: ["marko"],
compilerOptions: DEFAULT_COMPILER_OPTIONS
}
Thanks for creating the issue, hopefully this answer is sufficient 😄.
Perfect guys, thanks!
Short question! I've seen both of the below lines of code here and there. I'd just like to know which one I should be using: