You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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!
The text was updated successfully, but these errors were encountered:
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
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:
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:
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 forpug.compileFileClient
to remove the existing inline ones, the template functions now callspug.attr
for example instead ofpug_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:
pug/packages/pug-code-gen/index.js
Line 90 in d4b7f60
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!
The text was updated successfully, but these errors were encountered: