tscompilr
v1.0.5
Published
This is a utility for transpiling TypeScript files to equivalent JavaScript files.
Downloads
15
Maintainers
Readme
tscompilr
This is a utility for transpiling TypeScript files to equivalent JavaScript files.
Prerequisite
Installation
With npm
:
npm install tscompilr --save
With yarn
:
yarn add tscompilr
Usage
In order to use tscompilr
, do the following:
CommonJS
const { compile } = require("tscompilr");
/* Array of files */
const files = ['src/file-a.ts', 'src/file-b.ts', ...];
/* Every valid TypeScript compiler options is allowed. */
const compilerOptions = {
module: "commonjs",
outDir: "dist",
noEmitOnError: true,
rootDir: "src"
};
/* transpile */
compile(files, compilerOptions, skippedTranspiling =>{
if(!skippedTranspiling){
console.log("Files successfully transpiled")
}
})
ES6
import { compile } from "tscompilr";
/* Array of files */
const files = ['src/file-a.ts', 'src/file-b.ts', ...];
/* Every valid TypeScript compiler options is allowed. */
const compilerOptions = {
module: "commonjs",
outDir: "dist",
noEmitOnError: true,
rootDir: "src"
};
/* transpile */
compile(files, compilerOptions, skippedTranspiling =>{
if(!skippedTranspiling){
console.log("Files successfully transpiled")
}
})
TypeScript
import { compile } from "tscompilr";
import ts from "typescript";
/* Array of files */
const files:string[] = ['src/file-a.ts', 'src/file-b.ts', ...];
/* Every valid TypeScript compiler options is allowed. */
const compilerOptions:ts.CompilerOptions = {
module: ts.ModuleKind.CommonJS,
outDir: "dist",
noEmitOnError: true,
rootDir: "src"
};
/* transpile */
compile(files, compilerOptions, (skippedTranspiling:boolean) =>{
if(!skippedTranspiling){
console.log("Files successfully transpiled")
}
})
Running Tests
$ npm run test
or
$ yarn test
Check the scripts key in package.json
for the complete list of targets.