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

Minimize payload size #3

Closed
w0rm opened this issue Aug 8, 2014 · 5 comments
Closed

Minimize payload size #3

w0rm opened this issue Aug 8, 2014 · 5 comments

Comments

@w0rm
Copy link
Contributor

w0rm commented Aug 8, 2014

nunjucksify adds a bunch of code to every module. This is a no go for bundles with many tiny templates.

Maybe introduce an option to rely on nunjucks.env to get templates rather than mock getTemplate for every module?

@w0rm
Copy link
Contributor Author

w0rm commented Aug 17, 2014

I have managed to simplify template compilation code a little bit by using nunjucks.compiler.compile directly. So the trick with window overriding and precompileString is not needed anymore. This code is now merged in #4 PR.

@lennerd
Copy link

lennerd commented Mar 14, 2015

Hey @w0rm,
hey @dgbeck,

I'm a bit confused why we need this bunch of code (like you @w0rm said, it's kind of a no go for many tiny templates), to give browserify a hint where the other templates are.

So I created my own transformer inspired by your one. Before I will start making a PR for this changes, I would like to know, what you guys think about my approach of handling required template paths.

https://gist.github.com/lennerd/78fe961391c20c1ba6ed

What I basically did, was to not override the getTemplate function, but to store the required templates and add simple require statements at the beginning of the compiled template module if needed. Next I replaced all the template names with unique template id strings, so nunjucks can store and get all the required templates from the nunjucksPrecompiled object.

If you have any questions please ask. I'm really interessted in your opinion on that.

@w0rm
Copy link
Contributor Author

w0rm commented Mar 14, 2015

@lennerd hi! Does your code pass all the tests?

@lennerd
Copy link

lennerd commented Mar 14, 2015

I'm relativly new to unit tests in JS. Can you give me an example to run the mocha tests?

When I run the tests with $ mocha only the last one is passing:

1) Renders the same in node and in dom
2) Correctly extends block
3) Correctly compiles recursive dependencies
4) Accepts custom file extension as string
5) Accepts custom file extension as array
✓ Prevent duplicate require calls for the same template (253ms)

I always get the same error from the jsdom library.

Uncaught TypeError: Cannot set property length of [object Object] which has only a getter

Did I miss something?

@lennerd
Copy link

lennerd commented Mar 14, 2015

Ah, this tests fail with the original code. So no new code applied or added.

@w0rm w0rm closed this as completed Dec 16, 2017
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

2 participants