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

pug.compiledFileClient() with inlineRuntimeFunctions: true changes how compiled templates call runtime functions. #3374

Open
fatchan opened this issue May 22, 2022 · 0 comments

Comments

@fatchan
Copy link

fatchan commented May 22, 2022

Pug Version: 3.0.2

Node Version: 16.14.2

Additional Comments

Hi, so I use a number of compiled templates for the browser side with pug.compileFileClient. This works great, but I noticed the pug runtime functions (pug_*) are inlined in each one and this adds ~10KB to the total script size. I would like to share those functions between all the templates rather than duplicate them.

I checked the pug-runtime readme that generates those inline runtime functions and the readme says:

You can also build a string with a given list of functions available as pug_method by calling build(arrayOfMethods). This is useful for inlining runtime functions within the compiled templates.

So instead of having duplicated runtime functions I made note of what runtime functions were used across all my templates and did as the readme shows to generate the string of pug_ runtime functions like:

var build = require('pug-runtime/build');
var src = build(['attr', ...]);

And then I included that code before all the compiled templates in my frontend script. This would work BUT when I set inlineRuntimeFunctions: false in the options for pug.compileFileClient to remove the existing inline ones, the template functions now calls pug.attr for example instead of pug_attr so it can't use my shared runtime functions.

I modified 1 line in pug-code-gen to not change pug_ to pug. depending on inlineRuntimeFunctions, and everything worked as expected:

return 'pug.' + name;

Is it possible to have an option added such that when you set inlineRuntimeFunctions: false it doesn't change how compiled templates call the pug runtime? (or is there another way to do what i want?)

Thanks!

@fatchan fatchan changed the title compiledFileClient inlineRuntimeFunctions change how compiled templates call runtime functions. pug.compiledFileClient() with inlineRuntimeFunctions: true changes how compiled templates call runtime functions. May 24, 2022
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

1 participant