-
Notifications
You must be signed in to change notification settings - Fork 641
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
Node env support pre-compiled templates #337
Conversation
Why do you want to precompile templates in node? They are cached so they are only compiled on the first load, and from then on always are loaded from the cached versions. |
You mentioned something here: #302 (comment) but can you elaborate? When can you not use the |
Because on some cloud env, they do not support use fs module to locate the 2015-01-09 5:20 GMT+08:00 James Long [email protected]:
Ulion |
Hey @ulion, it's great that you used my PR! :D I submitted a PR to your PR (Yo dawg!). In it you can clearly see the motivation for my PR - the ability to store precompiled templates in modules. Also, the browser doesn't get the checks for node env neither the other way around. |
@rhengles Did a great clean PR on my PR, I merged that and added cmd parameter for the bin/precompile command, now user can compile templates as module by bin/precompile -w cjs-module template-folder > template.js |
Oh, wait, the compiled template seems not directly work, I need adjust code still. |
OK, the code is good, just the code to include the compiled template need adjust: before recent changes in this PR: now: |
ok, will try to that now. 2015-04-28 6:22 GMT+08:00 James Long [email protected]:
Ulion |
@jlongster rebased. |
I'm still iffy about including all of this in nunjucks by default. Seems like a good candidate for a separate module, and I'm happy to add in whatever hooks needed to make that possible. I'll take a look at this again tomorrow though and give it a second though. |
You can think of it like a webpack loader: the precompile script can take a "wrapper" that resolves to a node module that nunjucks calls out to. That way all of the CJS-specific stuff is in a separate module and you would just invoke it like |
browser and nodejs env is the 2 basic use env of the nunjucks, there seems 2015-04-28 8:56 GMT+08:00 James Long [email protected]:
Ulion |
In the (near?) future, we'll need to add formatters for ES6 modules, and there's also AMD (and God forbid, UMD). I understand @jlongster 's opinion. It would be a more powerful abstraction and cleaner, too. |
ops, I have no idea about that. If so, how do we implement required functions for what current PR does? I 2015-04-28 9:03 GMT+08:00 Rafael Hengles [email protected]:
Ulion |
The reason for supporting browser precompilation out of the box is because it's not only the most common usage or precompilation, it's required for production use. Nunjucks has been around for years and this is the first request I've heard for other environments, so it's just a far less common case. The precompile API exists so that you can do anything you want with it, and nunjucks doesn't have to worry about support more formats. I do see potential in being able to specify the format at the command line and it automatically invokes your custom formatter to make sharing formatters/loaders easy. I'll whip up a patch to show you what I mean. |
This is what I'd like to merge instead: #418 I went ahead and added in the Now, just create a new modules, say |
Let's move discussion over to #418 |
This PR based on #302
by adopting the wrapper of compiled template, the compiled templates now support be loaded in Node env by the PrecompiledLoader.