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

Function "compileBody" exported for external use #2905

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mitroofann
Copy link

@mitroofann mitroofann commented Nov 12, 2017

I wanted to prepare compiled functions for exchanging between my applications: one app compiles the 'pug' function (a prepared string of function, when using "compileBody"), the other receives a it and builds the function. ('pug' files of my projects are stored on a server "1", but web-server is a server "2").

server 1:

const funcBody = require('mitroofann-pug').compileBody(
	file,
	{
		basedir               : path.parse(filename).dir,
		filename              : filename,
		debug                 : false,
		compileDebug          : false,
		cache                 : false,
		inlineRuntimeFunctions: true
	}
).body;

Server 2:

const script  = require('vm').createScript(funcBody);
const context = require('vm').createContext({});

script.runInContext(context);

const render = context.template;

@rollingversions
Copy link

rollingversions bot commented May 1, 2020

There is no change log for this pull request yet.

Create a changelog

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

Successfully merging this pull request may close these issues.

1 participant