This loader is intended to show very quickly how to use the proposed NodeJS 9.0.0 loader API to be able to compile TypeScript files on demand. It is not a stable solution in any way.
The proposed way of using the loader is as follows:
node --experimental-modules --loader ./loader.mjs imports.js
You will need to build a special version of NodeJS until this feature is released.
So you will likely need to use something like:
./node --experimental-modules --loader ./loader.mjs imports.js
Which means that by all means, this should not be used in any distributions at this point.
At this time, NodeJS 9.0 is still not released but can be manually built by checking out a specific branch from GitHub and working from there.
Checking out Guy Bedford's branch
Until a more stable branch is locked in we are resorting to the PR branch used by Guy to introduce the new declarative loader feature.
» git clone https://github.com/guybedford/node.git -b resolve-hook-rebased --single-branch
This will download roughly 275 MB's instead of over 3GB.
Building
NodeJS has a well documented BUILDING process in their repo on GitHub. However, you don't have to follow the entire process as outline, just pick the parts that will get you to a working node.
Keep in mind that you will likely repeat this process more than once until the point where it becomes a public release, so find a reproducable simple workflow.
Here is what I did on macOS High:
» git clone https://github.com/guybedford/node.git -b resolve-hook-rebased --single-branch node-gb
» cd node-gb
» ./configure
» make -j4
» ./node -e "console.log('Hello from Node.js ' + process.version)"
Here is a more up-to-date procedure:
» git clone https://github.com/guybedford/node.git -b resolve-hook-rebased --single-branch node-gb
» cd node-gb
» ./configuregit reset --hard 0bd9e6fa71b1baf54703e40c9b519b04f5b49197
» ./configure
» make -j4
» ./node -e "console.log('Hello from Node.js ' + process.version)"
or simply:
» git clone https://github.com/guybedford/node.git -b resolve-hook-rebased --single-branch node-gb; cd node-gb && git reset --hard 0bd9e6fa71b1baf54703e40c9b519b04f5b49197
» ./configure; make -j4; ./node -e "console.log('Hello from Node.js ' + process.version)";