marko icon indicating copy to clipboard operation
marko copied to clipboard

Short question: require('marko/node-require'); or require('marko/node-require').install(); ?

Open basickarl opened this issue 8 years ago • 4 comments

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:

require('marko/node-require');
require('marko/node-require').install();

basickarl avatar Oct 29 '18 10:10 basickarl

@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.

ravitadi avatar Oct 30 '18 21:10 ravitadi

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.

  • [ ] https://markojs.com/docs/installing/
  • [ ] https://markojs.com/docs/huncwot/
  • [ ] probably more

balupton avatar Nov 06 '18 08:11 balupton

@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 😄.

DylanPiercey avatar Nov 18 '18 03:11 DylanPiercey

Perfect guys, thanks!

basickarl avatar Nov 18 '18 10:11 basickarl