Sample use of a .htaccess file in order to compile TypeScript files on-the-fly using PHP.
You only need to write script.ts
in your HTML and the request will be forwarded to the PHP script.
This script will then load a cached version or recompile it.
- Install Node.js if you have not done yet: http://nodejs.org/.
- Install TypeScript using NPM:
npm install -g typescript
. - Put the whole repository on your (local) server.
- Open
http://your.server/ts-htaccess/index.html
in your browser.
If you want the output to get written into a file:
TSCompiler::compile($options, $errorInfo);
And if you just want a string:
$str = TSCompiler::compileToStr($options, $errorInfo);
The passed $options
array can contain two values at the moment:
$options['inputFile']
The input file$options['outputFile']
The output file which won't be used if you call the string function variant.
You can also specify a temp directory in the class file.
The files which are temporarily generated by TSCompiler::compileToStr()
will be saved for a very short moment in this location.