Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to assign a function directly to query.config #39

Closed
ghost opened this issue Sep 28, 2016 · 3 comments
Closed

Allow to assign a function directly to query.config #39

ghost opened this issue Sep 28, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Sep 28, 2016

Is it possible to, instead of passing a path to a module that exports a function, pass the function directly to the query.config option?

I think it would be great to be able to do something like

....
{
  test: /\.html$/,
  loader: 'nunjucks',
  query: {
    config: function (env) { ... }
  },
}
...
@at0g
Copy link
Owner

at0g commented Sep 28, 2016

It would be nice, but...
The query is a string, and can also be used inline require('nunjucks!tpl.njk?config=...').
It might be possible with eval (provided the supplied value is a string rather than a function), but I can see that approach coming with it's own set of problems.

@at0g at0g added the question label Sep 28, 2016
@ghost
Copy link
Author

ghost commented Sep 29, 2016

I may be misunderstanding something here, but I looked at the source and there is this chunk of code

if (query.config) {
  pathToConfigure = query.config;
  try {
    var configure = require(query.config);
    configure(env);
  }
....

So I tought it would be possible to do something like this

if (query.config) {
  pathToConfigure = query.config;
  try {
    var configure   
    if (typeof query.config === 'function')
      configure = query.config;
    else
      configure =  require(query.config);
    configure(env);
  }
....

I've forked this repo and tried to do this myself but, for some reason I really don't undestand, I couldn't get the tests to work in my machine.

@at0g
Copy link
Owner

at0g commented Oct 21, 2016

@vtfn
What was the problem you had with the tests - maybe I can help you out with that?

Regarding your previous comment:

console.log(typeof query.config === 'string') // always true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant