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

Create 4x branch #60

Open
at0g opened this issue Jan 25, 2018 · 8 comments
Open

Create 4x branch #60

at0g opened this issue Jan 25, 2018 · 8 comments

Comments

@at0g
Copy link
Owner

at0g commented Jan 25, 2018

Disclaimer:
While I maintain this repo, I don't use nunjucks and have not done so for several years now. It does not suit my style of work, but I can appreciate that it may be good for others. If you would like to step up to become a maintainer of this package, contributing to this release would be the way to go.

I have started working on a 3.x 4.x version of this module, which can be seen here:
https://github.com/at0g/nunjucks-loader/tree/3x

Currently the new branch has a working example using html-webpack-plugin; along with a browser only version.

As of nunjucks@2, their packaging approach is literally hostile to UMD.
This makes it very difficult to support code that runs in the node environment (html-webpack-plugin, extract-text-plugin etc). Instead, I have opted for the following approach:

  1. Precompile all of the template strings (almost environment agnostic) within the loader
  2. Use the browser slim version in both browser and node environments

The caveat is this:

if (target === 'node') {
    // perform some messy crap to use the nunjucks precompiled loader in node. 
    const window = global.window || {};
    window.nunjucksPrecompiled = false;
    global.window = window;
}

My concern with doing this is that it's fairly common to branch other code based on typeof window !== 'undefined'.

@chrisfarms
Copy link

I was just trying to solve this problem (making a loader for node-side that plays nicely with html-loader). It looks like I'll be using nunjucks for some time at work so I might be interested in helping out on this project.

I took a slightly different approach by parsing the templates during the "pitch" phase so that we can collect all the required templates sources and use a custom Loader to pull them out of the require system.... it wasn't pretty... but it works.

It's a shame there's no way to fully precompile the templates AND support other loaders since I'm sure there's some tree shaking that we will miss out on.

Anyway... I just pushed a PoC here: https://github.com/chrisfarms/njk-loader

Since I don't need browser compilation I didn't even attempt to solve that, but the same technic should work.

Let me know if you think this might be a good direction for nunjucks-loader and I'll have a go polishing it up into a PR with tests/browser support.

@at0g
Copy link
Owner Author

at0g commented Feb 5, 2018

@chrisfarms Thanks for your input.
A custom Loader that leverages require sounds like a better approach than rewriting the runtime... so yes, I think this could be a good direction :)

Give me a week (to find some time) and I will update the sibling packages in the 3.x branch with test suites for specific scenarios (node, browser, umd, template inheritance, filters, macros etc).

@bonesoul
Copy link

bonesoul commented Mar 2, 2018

how about webpack 4.x support?

@chrisfarms
Copy link

I continued to mature the version I was working on at chrisfarms/njk-loader#2 ... it should now work for browsers and webpack 4 ... hopefully I'll find some time this weekend to finish up adding tests ... but if @at0g can get some test in here I'd be happy to port it over to here rather than creating yet another loader.

@at0g
Copy link
Owner Author

at0g commented Mar 2, 2018

@chrisfarms - sorry about the delay... there is a lot going on with life at the moment. I'll try for tests this week. Failing that, I agree with not creating another loader, so will gladly hand over the module name if you want to maintain it.

@chrisfarms
Copy link

Thanks at0g ... I'd def be interested in taking over maintaining the module if you're not very active in the nunjucks space these days.... however what would be even better for the community is if I can get my workplace to adopt the project ... they are using nunjucks in a few projects so I'll see if I can drum up some support

@at0g at0g changed the title Create 3x branch Create ~~3x~~ 4x branch Mar 6, 2018
@at0g at0g changed the title Create ~~3x~~ 4x branch Create 4x branch Mar 6, 2018
@danielpza
Copy link

@chrisfarms any updates ?

@mdmoreau
Copy link

mdmoreau commented Jan 4, 2019

@at0g @chrisfarms Are there any updates on this? Trying to decide on a template engine and loader, so figured I'd drop a quick message here.

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

No branches or pull requests

5 participants