Using JSRT, how do you load a module and then use it?

191 Views Asked by At

Using the JavaScript Runtime (JSRT), what functions would you call to load a JavaScript module and then call functions on it. For example, how would I load the file C:\Users\camer\ts\TsAst\node_modules\typescript\lib\typescript.js and then access ts.version to return 2.4.2?

1

There are 1 best solutions below

0
On

There's a great example in the Chakra-Samples repository for both C++ and C#. If you're embedding on Linux, *BSD, or MacOS, you can modify the build script for above sample in line with the Hello World example in the same repository.

For a real-world example, check out how React Native Windows embeds ChakraCore by loading React Native JavaScript bundles using the same APIs as the samples. If you want to get fancy and do bytecode bundles to speed up app launch and time-to-interaction, React Native Windows' implementation can be used as a reference for that advanced use case as well.