We will locate the source files in lib
and the tests in lib/test
. We use gulp
to compile the project and AVA to run tests. We can install the dependencies of our project with NPM:
npm init -y npm install ava gulp gulp-typescript --save-dev
In gulpfile.js
, we configure gulp
to compile our TypeScript files:
var gulp = require("gulp"); var ts = require("gulp-typescript"); var tsProject = ts.createProject("./lib/tsconfig.json"); gulp.task("default", function() { return tsProject.src() .pipe(ts(tsProject)) .pipe(gulp.dest("dist")); });
We can download type definitions for NodeJS with NPM:
npm install @types/node --save-dev
We must exclude browser files in TypeScript. In lib/tsconfig.json
, we add the configuration for TypeScript:
{ "compilerOptions": { "target": "es6", "module": "commonjs" } }
For applications...