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

Failure when combining nunjucks-loader and file-loader. #24

Open
ghost opened this issue Feb 27, 2016 · 15 comments
Open

Failure when combining nunjucks-loader and file-loader. #24

ghost opened this issue Feb 27, 2016 · 15 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Feb 27, 2016

Loader generated modules should respect the same design principles like normal modules.
Example: That’s a bad design: (not modular, global state, …)

require("any-template-language-loader!./xyz.atl");
var html = anyTemplateLanguage.render("xyz");

I tried to combine with file-loader, but is not working:

...
{
  test: /\.(nunj|nunjucks)$/,
  loader: 'file!nunjucks'
}
...

Reference: https://webpack.github.io/docs/how-to-write-a-loader.html#generate-modules-that-are-modular

@at0g
Copy link
Owner

at0g commented Feb 27, 2016

I don't really get your use case for chaining file and nunjucks loaders together - can you explain what you're expecting to happen?

In regards to modular design that you've linked to, I don't see how this could be possible with nunjucks due to how template dependencies are resolved.

@at0g
Copy link
Owner

at0g commented May 4, 2016

Hello @patrickporto Any feedback at all or just trollin`?

@ghost
Copy link
Author

ghost commented May 5, 2016

My expectation is that:

  • Compile HTML with Nunjucks.
  • Export file to output directory.

@bobbrez
Copy link

bobbrez commented Jun 2, 2016

The title of the issue is a bit vague, but I'm looking at @patrickporto's same use case.

@patrickporto patrickporto changed the title Bad design Failure when combining nunjucks-loader and file-loader. Jun 3, 2016
@ghost
Copy link
Author

ghost commented Jun 3, 2016

@at0g, I've changed and the title and the description as requested. Sorry about any misinterpretation. English is not my mother tongue.

@at0g
Copy link
Owner

at0g commented Jun 6, 2016

@patrickporto thanks for cleaning up the title.
@bobbrez / @patrickporto - thanks for reporting your use case. I'm not convinced this functionality should be a part of this loader... let me think on it. There is an another way (using an intermediate file) that will do what you're after - I'll try to create an example or gist either tonight or tomorrow.

@bobbrez
Copy link

bobbrez commented Jun 6, 2016

@at0g Thanks

@at0g
Copy link
Owner

at0g commented Jun 8, 2016

There is an another way (using an intermediate file) that will do what you're after

Not as easy as I'd hoped for... I've burnt a few hours tonight trying to get an intermediate method to work and haven't got very far 👎

Probably won't get a chance to look at it again before next weekend... pretty sure this needs to be a separate project to make it work.

Can either (or both) of you post here with a bit more information about what you're trying to do... specifically with some info about how you'd like to pass data and configure nunjucks.

@at0g at0g added wontfix and removed enhancement labels Jun 8, 2016
@at0g at0g self-assigned this Jun 8, 2016
@dfdgsdfg
Copy link

dfdgsdfg commented Aug 31, 2016

Maybe nunjucks-html-loader can compile nunjucks to html.

Or static-site-generator-webpack-plugin?

@daslicht
Copy link

when using sass / fontawesome you need the file-loader as well

@at0g
Copy link
Owner

at0g commented Nov 17, 2016

when using sass / fontawesome you need the file-loader as well

@daslicht
You can use other loaders within the nunjucks templates

@daslicht
Copy link

ahh so you pass a loader to nunjucks loader

@at0g
Copy link
Owner

at0g commented Nov 17, 2016

it provides a require filter that hooks into webpack. Provided you have the loader configured, it will return whatever webpack resolves from the require statement.

eg.

# tpl.njk
{{ 'file!./relative-path/to/image.jpg' | require }} # outputs "/images/image.jpg"

{{ 'raw!hello-world.txt' | require }} # outputs "Hello world"

@vacchi
Copy link

vacchi commented Nov 23, 2017

im still getting a issue:
./src/templates/includes/header.njk
Module not found: Error: Can't resolve './images/image.png'

{{'file-loader!./images/image.png' | require}}
and on webpack:

{
          test: /\.(njk|nunjucks)$/,
          loader: 'nunjucks-loader'
      }

do you have any Ideas?

@at0g
Copy link
Owner

at0g commented Nov 26, 2017

@vacchi I presume src/templates/includes/images/image.png does exist?
If the path is correct (eg. you still have this issue) can you please share a reproduction and I'll look into it.

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

No branches or pull requests

5 participants